When using the Partners Jupyterhub server (https://jupyterhub.partners.org), users are able to create and launch their own conda virtual environments. This workflow will advise users on how to create their own conda virtual environment and add it to their Jupyterhub.
Creating A Conda Virtual Environment
To begin, a conda virtual environment needs to be created in your ERISOne account. If you do not already have a virtual environment, the next steps will walk through it. It is best to use the same version of Anaconda as we have on the Jupyterhub server. In this walk through, we will be using Anaconda3 version 5.2.0.
module load Anaconda3/5.2.0
mkdir -p $HOME/anaconda3/envs
conda create -p $HOME/anaconda3/envs/myenv
Please note that the ‘conda create’ command only supports ‘—name <name>’ or ‘-p <path>’, but not both.
Install packages in your custom environment, using “conda install”. Be sure to include the “jupyter” conda package. Create a Jupyter kernel based on your environment.
source activate $HOME/anaconda3/envs/myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
Adding The Virtual Environment To Jupyterhub
At this point your virtual environment will be visible as a kernel in Jupyterhub, but will not function as expected. The Python modules path from your virtual environment need to be added to the kernel file that was created in the step above.
Go to your custom kernels folder and locate the newly created kernel.json file
find . -name kernel.json
Backup the file and edit it to add an “ENV” section, that sets “PYTHON_PATH” to point to “side-pacakges” in your conda virtual environment. It will look something like this. (Be sure to replace “abc123” with your username!)
"display_name": "Python (myenv)",
Now, you should be able to work in your custom environment within Jupyterhub!