HOWTO: Use a Conda/Virtual Environment With Jupyter

Conda/Virtual environments must be installed on JupyterLab or Jupyter Notebook prior to use. Whereas older versions of Conda automatically installed a Jupyter kernel, users must now manually perform the installation process.

To perform the installation, users should load the preferred version of Python, activate the Conda/Virtual environment and run the following commands.

See create conda/virtual environment if there is not already an environment that has been created.
# change to the proper version of python
module load python  

# replace with the name of conda env           
MYENV='useful-project-name'    

# Activate your conda/virtual environment
## For Conda environment
source activate "$MYENV"

## For Python Virtual environment
source /path/to/$MYENV/bin/activate

# Install Jupyter kernel 
python -m ipykernel install --user --name "$MYENV" --display-name "Python ($MYENV)"

If the envirnoment is rebuilt or renamed, users may want to erase any custom jupyter kernel installations.

Be careful! This command will erase entire directories and all files within them.
rm -rf ~/.local/share/jupyter/kernels/$(MYENV)

 

Supercomputer: 
Service: