Python & Jupyter
Table of contents
Python environments with conda
The conda package manager is the recommended approach for Python projects, especially those that rely on native libraries (e.g., machine learning). Conda creates isolated “environments” for each project, with specific versions of Python and the packages it needs, without requiring administrative privileges.
By default, conda uses the official “defaults” repository. To find additional packages, add the conda-forge repository.
To create and activate a new environment named my_py_env (the name is arbitrary) with Python 3.12 (leave out the version to get the current stable release):
conda create --name my_py_env python=3.12
conda activate my_py_env
With the environment activated, you can install additional packages with conda, e.g.,
conda install numpy
or with pip (activating the environment updates your PATH so python3 is the environment’s Python):
python3 -m pip install numpy
Once you have created an environment, you only need to activate it to use it again. SLURM jobs inherit your current environment, so a job submitted with an activated conda environment will use that environment.
Miniforge
Miniforge is a beta feature that requires enabling Lmod.
The existing Anaconda-based conda installation will eventually be replaced by Miniforge, a free, minimal conda installation that uses the open-source conda-forge repository by default. The conda commands above work the same way. To use it:
module load miniforge
To add other repositories (e.g., bioconda), run conda config --add channels bioconda.
Jupyter
The Jupyter application is a beta feature of Open OnDemand.
You can run JupyterLab or Jupyter Notebook on a compute node through Open OnDemand. Log in to ood.middlebury.edu, select Interactive Apps > Jupyter, and fill in the form. In addition to the common fields (node type, hours, cores, memory), you can choose:
| Field | Description |
|---|---|
| Python Version | Python 3.12 or 3.14 |
| Mode | JupyterLab (recommended) or the classic Jupyter Notebook interface |
| Root Directory | The folder Jupyter opens in, e.g., your project folder in /storage/username. Defaults to your home directory. |
Click Launch, and once the session is running, Connect to Jupyter. Remember to Delete the session when you are finished.
Installing packages in Jupyter
The Jupyter environments are intentionally minimal: they include Python and Jupyter, but not packages like NumPy or pandas. Install what you need from a notebook cell with %pip, e.g.,
%pip install numpy pandas matplotlib
and then restart the kernel. You can also run pip install in a Jupyter terminal. Packages are automatically installed into a personal directory in your home directory (under ~/.local/jupyterlab/), separate for each Python version, so they remain available in future sessions. pip will refuse to install a package version that conflicts with Jupyter’s own packages.
To use the same Python environment in a batch job (including the packages you installed), enable Lmod and load the matching module in your job script, e.g., module load jupyterlab/4.2.5-python3.12.
Using your own conda environment in Jupyter
To use a conda environment you created (see above) as a Jupyter kernel, install ipykernel in that environment and register it (you only need to do this once):
conda activate my_py_env
conda install ipykernel
python -m ipykernel install --user --name my_py_env --display-name "Python (my_py_env)"
“Python (my_py_env)” will now appear as a kernel choice in Jupyter.
GPU-enabled libraries
See the Torch page for installing GPU-enabled PyTorch, and Working with GPUs for requesting GPUs.
Table of contents
- Torch - Installing GPU-enabled PyTorch (Torch) via Conda and Pip.