Frequently Asked Question
How can I have a workspace with specific versions of Python packages?
Last Updated 3 years ago
You can use virtual environments to install specific versions of packages and install a custom Jupyter kernel to use them in your interactive notebooks.
- Open a terminal from the launcher.
- Go to the directory where you want to store your virtual environment.
cd the/directory/you/want
- Create the virtual environment (change
myenv
with the name you want).python -m venv myenv --system-site-packages
The--system-site-packages
flag allows the packages installed on the platform to remain accessible in the virtual environment. If you want a clean environment do not use this flag. - Activate the virtual environment.
source myenv/bin/activate
- Register the virtual environment with JupyterLab.
python -m ipykernel install --user --name=myenv
The virtual environment will be listed in the launcher and kernels list once you log out and log in again. - Install packages you want.
pip install package==version pip install package==version
- Exit the virtual environment.
deactivate
- If you need to install additional packages later, activate the virtual environment and install packages as indicated above.
- You can un-register the virtual environment at any time.
jupyter kernelspec uninstall myenv
- You can remove the virtual environment by removing its directory.
rm -rf myenv
- Some packages may require system-wide libraries to be available. If you encounter any errors while installing packages please contact us.
Further Reading: