Skip to content

Instantly share code, notes, and snippets.

@sgsfak
Last active July 11, 2023 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgsfak/de0898743050d78a1ab87339cee31c18 to your computer and use it in GitHub Desktop.
Save sgsfak/de0898743050d78a1ab87339cee31c18 to your computer and use it in GitHub Desktop.
venv and jupyterlab

Creation of the virtual environment using venv

Assuming that you have a recent Python version installed (eg. using your Linux package manager or by downloading one), first I create a virtual env like so:

python -m venv venv

NOTE: For this to work in Ubuntu Linux you probably need to also install python3-venv using apt

After that we activate the virtual environment using :

source venv/bin/activate

(or issuing venv\Scripts\activate.bat in Windows)

Then we can install any Python package using pip in this venv, issuing either python -m pip install <package> or just pip install <package>

NOTE: Especially if we install packages with command line scripts (e.g. prefect, dvc), in order to make sure that they can be found in the PATH I issue a rehash (in Zsh) or hash -r (in Bash)!

Install JupyterLab

In the active virtual environment I do:

python -m pip install jupyterlab

and then install an "kernelspec" inside the venv:

python -m ipykernel install --name <name> --sys-prefix

(where <name> could be anything you want)

Then we can start JupyterLab (inside the venv) :

python -m jupyterlab

and select the new "kernel" when creating a Notebook.

We can always get the list of the available kernels:

python -m jupyter kernelspec list

or remove one from the venv:

python -m jupyter kernelspec uninstall <name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment