Create a Jupyter Virtual Environment: Difference between revisions

From UCSC Genomics Institute Computing Infrastructure Information

(Created page with "__TOC__ If you need a specific Jupyter environment, because maybe you need specific Python modules or something like that, you've come to the right place. == Find a Location to Install == You will want to install your Jupyter Virtual Environment somewhere accessible from the PRISM Compute Nodes and all the cluster nodes, so it will need to either be in your home directory or in '''/private/groups/[lab_name]''' somewhere. For this example I'll use my home directory, '...")
 
 
(2 intermediate revisions by the same user not shown)
Line 19: Line 19:
Next create the environment!
Next create the environment!


  cd jupyterhub_venv
  cd jupyter_venv
  python3 -m venv jupyterhub
  python3 -m venv jupyterhub


Line 58: Line 58:
You will want to click on the '''Advanced''' tab at the top.  When defining your notebook resources, under "Jupyter environment", select "Custom".  Then define your description and give the path to your '''/bin''' directory in your environment, as such:
You will want to click on the '''Advanced''' tab at the top.  When defining your notebook resources, under "Jupyter environment", select "Custom".  Then define your description and give the path to your '''/bin''' directory in your environment, as such:


[[File:Custom2.png|800px|frame|left|Custom Environment]]
[[File:Custom_env.png|800px|frame|left|Custom Environment]]


It will then launch a notebook based on that environment, and all modules and packages installed in that environment will be available.
It will then launch a notebook based on that environment, and all modules and packages installed in that environment will be available.

Latest revision as of 07:02, 23 May 2026

If you need a specific Jupyter environment, because maybe you need specific Python modules or something like that, you've come to the right place.

Find a Location to Install

You will want to install your Jupyter Virtual Environment somewhere accessible from the PRISM Compute Nodes and all the cluster nodes, so it will need to either be in your home directory or in /private/groups/[lab_name] somewhere. For this example I'll use my home directory, /private/home/weiler.

Create Your Virtual Environment

I'll be creating this Virtual Environment in my home directory (but create it wherever you deem necessary). So:

cd /private/home/weiler

Then create the directory for the environment to go in:

mkdir jupyter_venv

Next create the environment!

cd jupyter_venv
python3 -m venv jupyterhub

It will create an environment in /private/home/weiler/jupyter_env/jupyterhub.

Next we activate the environment:

source ~/jupyter_env/jupyterhub/bin/activate

Your prompt should now look something like this:

(jupyterhub) [weiler@mustard jupyter_venv]#

Install Requisite and Optional Packages

From there you will need to minimally install these three packages:

(jupyterhub) [weiler@mustard jupyter_venv]# pip3 install jupyterhub jupyterlab batchspawner

You will need those three packages to start. So definitely install those. You can additionally install any other python packages, such as:

(jupyterhub) [weiler@mustard jupyter_venv]# pip3 install numpy pandas

Exit Your Virtual Environment

To exit out of your virtual environment, simply do:

deactivate

and you should return to your regular shell.

Call Your Virtual Environment In JupyterHub

Once you login to JupyterHub on the cluster here:

https://jupyterhub.prism

You will want to click on the Advanced tab at the top. When defining your notebook resources, under "Jupyter environment", select "Custom". Then define your description and give the path to your /bin directory in your environment, as such:

Custom Environment

It will then launch a notebook based on that environment, and all modules and packages installed in that environment will be available.