Using Virtual Environments and Jupyter Notebooks in OnDemand

This information is part of a collection of information on 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 --name my_env --display-name "Python (my_env)"

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.