Using a Python environment in Jupyter: Difference between revisions

From Research Computing Center Wiki
Jump to navigation Jump to search
(Created page with "== Python environment == A Python environment is a type of virtual environment. Python environments are used to contain a set of software/packages that you install (via pip) into that environment that may be accessed any time you activate the environment. To learn more about Python environments, please see our wiki page on creating Python environments '''here.''' == Open OnDemand == Open OnDemand is a...")
 
Line 5: Line 5:
Open OnDemand is a web-based service that allows users to run software with a graphical user interface (GUI) such as Jupyter Notebook. Please see our wiki page on Open OnDemand [[OnDemand|'''here''']] to learn more.
Open OnDemand is a web-based service that allows users to run software with a graphical user interface (GUI) such as Jupyter Notebook. Please see our wiki page on Open OnDemand [[OnDemand|'''here''']] to learn more.


== Using a Conda environment in Jupyter ==
== Using a Python environment in Jupyter ==
These steps will allow you to access the software you install into a Conda environment within Jupyter Notebook running on Open OnDemand
These steps will allow you to access the software you install into a Python environment within Jupyter Notebook running on Open OnDemand


=== Create the Conda environment ===
=== Create the Python environment ===
Create your Conda environment and install any packages you will want to use.  
Create your Python environment and install any packages you will want to use.  
=== Install ipykernel ===
=== Install ipykernel ===
While your Conda environment is still activated, install ipykernel to your Conda environment with:
While your Python environment is still activated, install ipykernel to your Python environment with:


<pre class="gcommand">
<pre class="gcommand">
conda install ipykernel
pip install ipykernel
python -m ipykernel install --user --name=my_env
python -m ipykernel install --user --name=my_env
</pre>
</pre>
Note: change my_env to whatever the name of your Conda environment is. This is the name that you will see in Jupyter Notebook as an available kernel.
Note: change my_env to whatever the name of your Python environment is. This is the name that you will see in Jupyter Notebook as an available kernel.


=== Open Jupyter in Open OnDemand ===
=== Open Jupyter in Open OnDemand ===
Line 26: Line 26:
Once the job starts, click on Connect to Jupyter. This will open Jupyter in a new page in your browser. <br>
Once the job starts, click on Connect to Jupyter. This will open Jupyter in a new page in your browser. <br>


From here, click "new" and you should see the name of the ipykernel you created. Clicking on that will start a Jupyter notebook with a kernel that has access to all of the packages in your Conda environment.
For Jupyter versions < 7.0.0 please see below (for versions > 7.0.0, scroll down).


[[File:Load_condakernel.png|alt=|border|1111x1111px]]
From here, click "new" and you should see the name of the ipykernel you created. Clicking on that will start a Jupyter notebook with a kernel that has access to all of the packages in your Python environment.
 
[[File:Load_pythonkernel.png|alt=|border|1111x1111px]]
 
 
For Jupyter versions > 7.0.0 please see below.
 
From here, click File > new > notebook. A new Jupyter notebook will open and a window will appear titled "Select Kernel". Click the drop down menu and under "Start Other Kernel" you should see the name of your python environment. Clicking on that will start your Jupyter notebook with a kernel that has access to all of the packages in your Python environment.
 
[[File:New-jupyter-interface.png|alt=|border|1111x1111px]]
 
[[File:Load_new_pythonkernel.png|alt=|border|1111x1111px]]

Revision as of 16:09, 12 March 2025

Python environment

A Python environment is a type of virtual environment. Python environments are used to contain a set of software/packages that you install (via pip) into that environment that may be accessed any time you activate the environment. To learn more about Python environments, please see our wiki page on creating Python environments here.

Open OnDemand

Open OnDemand is a web-based service that allows users to run software with a graphical user interface (GUI) such as Jupyter Notebook. Please see our wiki page on Open OnDemand here to learn more.

Using a Python environment in Jupyter

These steps will allow you to access the software you install into a Python environment within Jupyter Notebook running on Open OnDemand

Create the Python environment

Create your Python environment and install any packages you will want to use.

Install ipykernel

While your Python environment is still activated, install ipykernel to your Python environment with:

pip install ipykernel
python -m ipykernel install --user --name=my_env

Note: change my_env to whatever the name of your Python environment is. This is the name that you will see in Jupyter Notebook as an available kernel.

Open Jupyter in Open OnDemand

Click on the Jupyter app in Open OnDemand and click launch at the bottom of the page to start a Jupyter Notebook session.

Once the job starts, click on Connect to Jupyter. This will open Jupyter in a new page in your browser.

For Jupyter versions < 7.0.0 please see below (for versions > 7.0.0, scroll down).

From here, click "new" and you should see the name of the ipykernel you created. Clicking on that will start a Jupyter notebook with a kernel that has access to all of the packages in your Python environment.


For Jupyter versions > 7.0.0 please see below.

From here, click File > new > notebook. A new Jupyter notebook will open and a window will appear titled "Select Kernel". Click the drop down menu and under "Start Other Kernel" you should see the name of your python environment. Clicking on that will start your Jupyter notebook with a kernel that has access to all of the packages in your Python environment.