thacoon's Blog

Using virtualenv with Jupyter Notebooks

· thacoon

When using a Jupyter I also want to use virtualenv to keep my different python environments isolated. But I always forget how I do this, so here is how.

Create a new virtual environment or enter an already existing one and install the ipykernel. The following code creates a new one, to enter an existing one use workon my_env.

1$ mkvirtualenv my_venv
2$ pip install ipykernel
3$ python -m ipykernel install --user --name my_venv

Then you can start your juypter lab or notebook in another terminal.

1$ jupyter lab
2$ jupyter notebook

Follow the generated link and choose the kernel called my_env.

If you need to install a python package, e.g. matplotlib, just install it into your virtual environment to be able to use it in jupyter.

1$ pip install matplotlib

Additional

If you are using ArchLinux, btw. it just got 18 years old (initial release was 11 March 2002), you can install Jupyter Notebook or Jupyter Lab via pacman.

1$ sudo pacman -S jupyterlab
2$ sudo pacman -S jupyter-notebook

#python

Reply to this post by email ↪