Using Virtual Environments and Jupyter Notebooks in OnDemand

This information is part of a collection of information on constructing and using virtual environments.

The information below applies to virtual environments made with Miniforge (i.e., conda virtual environments, CVEs) and to VEs made with pip-venv (the links to both methods are on this page: constructing and using virtual environments.

Follow these steps to use your VE in a Jupyter Notebook interactive session on OnDemand:

  1. Check for ipykernel installation. Ensure that ipykernel is installed in your environment. After activating your environment, you can run the pip freeze command to list all the installed libraries. If ipykernel is not listed, you can install it with the pip install ipykernel command.

  2. Set up the environment ‘Kernel’. Assuming your environment is named my_env, activate it and run the following command:

python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

This will create a Jupyter Kernel named “Python (my_env),” which allows you to use ‘my_env’ within your notebooks.

  1. Launch and select the Kernel in Jupyter Notebook. After launching Jupyter Notebook on OnDemand (refer to the video tutorial here), open your notebook, then go to ‘Kernel’ in the top menu bar, select ‘Change Kernel’, and choose ‘Python (my_env)’ kernel.