Python
Using Python virtual environments with venv
For Python specifically, you can set up a virtual environment, which acts
similarly to a personal module but for using Python packages. In these virtual
environments, you can install whichever Python packages you want using pip, and
the result exists as a directory that you can load into sessions. See the
following example for how you can create the virtual environment myenv
(you may use any name):
$ module load python # (1)!
$ python3 -m venv myenv
$ source myenv/bin/activate
$ pip install <my-python-package>
- This will load the cluster default python version. If you need a specific
version, you can instead use
module load python/3.12.4
.
Once the virtual environment is created, you can now run the source command to load it into a new session and use your Python packages such as NumPy or SciPy.
Using Python virtual environments with conda
A similar process can be used with miniconda to create and activate a conda environment
$ module load miniconda3
$ conda create --name <my-env>
$ conda init bash
$ conda activate <my-env>
$ conda install <my-python-package>
For more information, you can look at the conda env documentation
Jupyter Notebooks vs. .py
Files
We recommend using Jupyter notebooks for exploration and data visualization. Notebooks provide an interactive environment that’s ideal for experimenting and analyzing data. For larger scripts or batch jobs, .py
files are often a better fit, as they are easier to run on compute nodes in non-interactive sessions.
Running Jupyter Notebooks on a Compute Node
If you'd like to run a Jupyter notebook on a compute node, you can do so using the sjupyter
command. This requires an active virtual environment that includes Jupyter:
This allows you to access compute resources within a notebook environment for more intensive interactive work.