Installing Python packages

How do I install python packages for use in Jupyter notebooks?

To use python environments you've created on the command line in a Jupyter notebook, you'll need to create what is known as a 'kernel' for the environment. This allows Jupyter to see and use the corresponding environment.
Supercomputing FAQs
The most practical way to do this right now at MSI is using mamba to create an environment, and then make a kernel for that environment using ipykernel. A procedure for doing this might look like the following, where we create an environment for using the tensorflow package from the conda-forge channel.
 
First, let's create the base of the environment that we'll install into. I'm only installing python3 and tensorflow here, as well as ipykernel for creating our Jupyter kernel later, but you can add other packages you may need to the end of the 'conda create' command.
module load python3
mamba create --name my_tensorflow_env python=3 tensorflow ipykernel --channel conda-forge
Now, let's activate the new environment and create the kernel for it. You can change the display name to whatever would be useful for you.
source activate my_tensorflow_env
python -m ipykernel install --user --name my_tensorflow_env --display-name "Python 3 (my_tensorflow_env)"
After this procedure, you should be able to select the custom kernel as a python notebook type in Jupyter, and the tensorflow package (along with any others you may have installed to this environment) will be available for use in notebooks of that type.
 
To select the kernel from within a notebook, you can click the kernel menu on the top right of the screen:
 

 

You can then select the new kernel from the menu that pops up:

 

If you are creating a new notebook, you can select the tile corresponding to your environment on the notebook creation page:

 

There is more in-depth documentation about kernel creation and conda environment management at the following links:

Discover Advanced Computing and Data Solutions at MSI

Our Services