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) orhash -r
(in Bash)!
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>