EDAF75: Database Technology – installing and running Jupyter

Using jupyter in EDAF75

We'll use jupyter during some of the lectures and labs. It's a great piece of software, and I really think it could help you a lot when you take this course, but I'll also generate regular web pages with the problem sets for the labs, so you don't have to download and install jupyter.

Below are two alternative ways of installing jupyter, you can try out either of them, for Windows users I suspect using pixi might be the easiest way.

Installing jupyter on your own computer, using pixi

One way of installing jupyter is to use some tool which is compatible with the conda echosystem, such as pixi or miniconda (LU used to have anaconda installations, but they've become very expensive).

If you install pixi (see its website), you can then create a directory in which to run your notebooks by doing:

$ mkdir notebooks
$ cd notebooks
$ ... put your notebooks and database files in this directory ...

To set up jupyter in this directory, just run the following two lines once:

$ ... make sure you're in your notebooks directory ...
$ pixi init
$ pixi add jupyterlab jupysql

You can now add any notebooks and databases to the directory, and start jupyter lab with the command:

$ ... make sure you're in your notebooks directory ...
$ pixi run jupyter lab

You shouldn't run the pixi init and pixi add commands above more than once in your directory, then you can run notebooks in it as many time as you like.

Installing jupyter on your own computer, using uv

Python is a great programming language, but the tooling around it has for a long time been messy (there have been many different 'solutions', such as using pip, venv, poetry, …) – but in 2024 a new promising tool appeared: uv.

The instructions below would work with slight modifications without uv, but I think it might be a good idea to get accustomed to using uv (later in the course we'll write some Python code which requires external libraries, and then we'll use uv for that).

Using uv we can run jupyter in a couple of different ways (see here for more), a pretty safe way would be the following (which is actually based on venv and pip, but here handled by uv):

  • Create a directory in which you unpack your notebooks:

    $ mkdir notebooks
    $ cd notebooks
    

    You can now copy any notebook into the notebook directory, and use it from the jupyter program we're about to install.

  • Set up a 'virtual environment' in which to run jupyter:

    $ uv venv --seed                     # create a directory .venv, with some tools
    $ uv pip install jupyterlab jupysql  # install jupyter and a sql-extension
    

    This will install jupyter and jupysql, which is a library which allows us to write SQL queries inside our notebooks (instead of jupysql you could use ipython-sql, but I've had some problems using it in this context, so I think using jupysql is probably a safer bet). The installed programs, and some additional tools, will end up in the directory .venv/bin.

  • Run the locally installed jupyter program:

    $ .venv/bin/jupyter lab
    

    This starts a service which you can connect to in a browser (the browser probably pops up on your screen – if it doesn't, you can always copy the URL written by jupyter in the shell window, and open it in a browser).

After you've set up your environment as in the two first steps above, you can start jupyter directly (as in step 3) – jupyter should see all notebooks in your notebooks directory (the notebooks are the files with the .ipynb extension).