Python
Python is available on Midway through several distributions provided as modules. This page describes how to choose a distribution and manage packages and environments.
Keywords: Python, conda, mamba, virtual environments, uv, pip
Distributions
Different versions of Python on Midway are offered as modules. Choosing the right Python distribution is essential for reproducibility, ease of use, and compatibility with Midway resources. The table below summarizes the main options and when to use each.
| Distribution | Module Name/Version | Best for | Notes |
|---|---|---|---|
| Standard Python | python/3.11.9, python/3.8.0, python/2.7 (Midway3)python/3.9.18 (Midway2) |
Most research, production, reproducibility | Minimal, clean installs. Use for scripts, pipelines, and most research. |
| Miniforge (conda/mamba) | python/miniforge-25.3.0 |
Scientific computing, data science | Flexible, includes mamba for fast env/package management. |
| Anaconda | python/anaconda-2022.05 (Midway3)python/anaconda3-2021.05 (Midway2) |
Legacy, teaching, compatibility needs | Not recommended for research due to license restrictions and inode/storage issues. |
Quick advice:
- Use Standard Python for most research, scripting, and production workflows. It ensures a clean, reproducible environment.
- Use Miniforge if you need many scientific/data science packages or want to manage environments with conda/mamba.
- Use Anaconda only if required for teaching, legacy workflows, or compatibility needs. For research, prefer Standard Python or Miniforge.
Important: Anaconda Licensing and Inode Usage Issues
Anaconda has implemented commercial license restrictions for organizations with over 200 employees, affecting many academic institutions. Additionally, a full Anaconda installation can exceed 3GB in size and create over 100,000 small files, which quickly exhausts inode quotas. On Midway clusters, home directories have strict file-count (inode) quotas (300,000 files soft limit; see Quotas), and a single Anaconda installation can consume a large share of this quota, preventing you from creating additional files.
To see available versions:
module avail python
To load a module:
module load python/3.11.9 # Standard Python (recommended)
module load python/miniforge-25.3.0 # Miniforge (conda/mamba)
- For most users, start with Standard Python. If you need conda-style environments or many scientific packages, switch to Miniforge.
- Both Standard Python and Miniforge are fully supported and optimized for Midway clusters.
Why Miniforge over Anaconda?
Miniforge is strongly preferred over Anaconda for research computing on Midway clusters for several reasons:
- No license restrictions for any use, unlike Anaconda's commercial restrictions
- Significantly fewer files and inodes: Anaconda installations can exceed 3GB and create over 100,000 small files
- Smaller disk footprint: Requires less storage space in your quota
- Faster package installation with Mamba support
- Uses conda-forge by default for more up-to-date scientific packages
- Better performance on HPC environments with lower overhead
Managing Inode Usage with Conda Environments
If you use any conda-based distribution (Miniforge, Anaconda, etc.):
- Install environments in
/scratch/midway3/$USER/conda_envsrather than your home directory - Run
conda clean --allregularly to remove unused package caches - Limit the number of environments you create and maintain
- Use
quotato check your current file count (inode) usage - Consider Python virtual environments (venv) for smaller projects
Cache
Conda/Mamba
By default, conda/mamba caches downloaded packages under ~/.conda/pkgs, which can rapidly exhaust your home directory's inode and space quotas on shared systems.
Options to control the cache:
- Temporary cache (recommended on Midway)
- Minimizes inode usage; cache lives in a temporary location and is cleaned up automatically.
- Our Python modules honor
USE_CONDA_CACHE=0when set before loading the module. -
Example:
# Set before loading the Python module export USE_CONDA_CACHE=0 module load python/miniforge-25.3.0 -
Persistent cache (optional, for repeated installs)
- Keeps packages between sessions to speed up repeated environment solves/installs.
- Set a cache directory in project or scratch space; avoid
$HOME. - You can either set
USE_CONDA_CACHE=1(module convenience; must be supported by the modulefile) and/or explicitly point conda to a path usingCONDA_PKGS_DIRSor.condarc:# Choose a persistent location (recommended) export CONDA_PKGS_DIRS=/project/PI_NAME/USER/conda/pkgs # or /scratch/midway3/$USER/conda/pkgs # Persist via conda config (optional) conda config --add pkgs_dirs /project/PI_NAME/USER/conda/pkgs conda config --show pkgs_dirs - If your modulefile supports the toggle, you can also do:
export USE_CONDA_CACHE=1 module load python/miniforge-25.3.0 - Recommendation: Use project or scratch; do not keep caches in your home directory.
- To clean unused packages:
mamba clean --all # Remove unused package cache # or conda clean --all
UV
UV is a modern, fast alternative to pip for package management (available on both Midway2 and Midway3):
# Load modules
module load python/miniforge-25.3.0 # or other Python version
module load uv
# Create virtual environment (faster than venv)
uv venv myenv
# Activate
source myenv/bin/activate
# Install packages (much faster than pip)
uv pip install numpy pandas
UV cache: temporary vs persistent
- Temporary cache reduces inode usage and is a good default on shared clusters.
- Persistent cache speeds up repeated installs across nodes/sessions. If you want this, either:
- Use our module toggle
USE_UV_CACHE=1beforemodule load uv(if supported by the modulefile), or - Set an explicit path with
UV_CACHE_DIRto project/scratch (preferred):export UV_CACHE_DIR=/project/PI_NAME/USER/uv/cache # or /scratch/midway3/$USER/uv/cache - To minimize cache entirely for throwaway installs, you can disable caching:
export UV_NO_CACHE=1 - Note:
UV_NO_CACHEis an official uv environment variable and does not require a modulefile. See the uv documentation.
Compiled packages on Midway2
On Midway2, packages with native extensions (e.g., NumPy/SciPy) may require a newer GCC toolchain (e.g., errors like "NumPy requires GCC >= 9.3"). If you encounter this, either load an appropriate GCC module before installing, or prefer installing these packages via conda/mamba environments instead of uv pip.
Environments
Private
Suppose that you would like to install NumPy, Matplotlib, and pandas for your calculations. You should first create an environment in your own space and install these packages into this environment.
Since Python environments might contain many files and/or take up a lot of space, it is recommended that you create your environments somewhere outside your home folder such as /project or /scratch. Suppose that your PI has a space under /project/[pi-folder] and you have a folder under that location.
cd /project/[pi-folder]/[your-cnetid]
python -m venv my-venv
source ./my-venv/bin/activate
pip install matplotlib numpy pandas
Note that the base environment of the default python module already has many popular packages installed, including the above three packages. You can also create an environment and install packages with conda or mamba.
Store environments in project space, not home directory:
# Create environment in project space
conda create -p /project2/PI_NAME/USER/envs/myenv python=3.9
ln -s /project2/PI_NAME/USER/envs/myenv ~/.conda/envs/myenv
source activate myenv
# Or with uv (recommended for faster creation)
module load uv
cd /project2/PI_NAME/USER/envs
uv venv myenv
source /project2/PI_NAME/USER/envs/myenv/bin/activate
Store environments in project space, not home directory:
# Create environment in project space
conda create -p /project/PI_NAME/USER/envs/myenv python=3.11
ln -s /project/PI_NAME/USER/envs/myenv ~/.conda/envs/myenv
source activate myenv
# Or with uv (recommended for faster creation)
module load uv
cd /project/PI_NAME/USER/envs
uv venv myenv
source /project/PI_NAME/USER/envs/myenv/bin/activate
Alternatively, you can use export CONDA_ENVS_PATH=/project/PI_NAME/USER/envs:$CONDA_ENVS_PATH to let conda know where to search for your virtual environment.
Once your environment is set up the way you want, especially if it is in your scratch space, you may want to back it up to a YAML file (after activating the environment):
# Minimal spec (portable): only packages you explicitly installed
conda env export --from-history > environment.yml
# Full lockfile (exact builds; best reproducibility on the same platform)
conda env export > environment-full.yml
# For uv environments
uv pip freeze > requirements.txt
To recreate the environment from a YAML file:
# Using minimal spec (resolver may choose newer builds)
conda env create --prefix=/path/to/new/environment -f environment.yml
# Using full lockfile (recreate exact builds when available)
conda env create --prefix=/path/to/new/environment -f environment-full.yml
Note
Anaconda may sometimes cause issues with ThinLinc. If you are experiencing frequent, spontaneous disconnections from ThinLinc, remove any sections involving "conda" or "anaconda" from the file ~/.bashrc (in your home directory).
Shared
Once you load a Python distribution, you can list all available public environments with:
conda env list
source activate <ENV NAME>
<ENV NAME> is the name of the environment for a public environment,
or the full path to the environment if you are using a personal one. You can deactivate an environment
with:
conda deactivate
Why use source activate instead of conda activate (or mamba activate)?
conda activate/mamba activate require conda init, which edits your shell startup files (e.g., ~/.bashrc, ~/.bash_profile). Those edits can interfere with the module environment, non-interactive shells (batch jobs), and remote desktop sessions, and generally degrade the user experience on Midway. Using source activate (with the full env path or a symlinked name) avoids modifying startup files and works reliably across login, batch, and ThinLinc sessions.
Do not run conda init
Never run conda init on Midway. It modifies your shell startup scripts and can break module behavior, non-interactive shells, and ThinLinc sessions. Use source activate instead of conda activate.
With each Anaconda distribution, we provide a small selection of widely used environments. Many, such as
TensorFlow or DeepLabCut, should be loaded through their modules (i.e., module load tensorflow), which automate the loading of other
relevant libraries that are available as modules.
The python/miniforge-25.3.0 module comes with several pre-configured domain-specific environments. Each environment is optimized for a specific research domain. Here’s a quick comparison:
| Environment | Activation command | Best for | Core packages / Tools |
|---|---|---|---|
| sci | source activate sci |
Scientific computing, data analysis | numpy, scipy, pandas, matplotlib, seaborn, scikit-learn, JupyterLab, ipython, h5py, psutil |
| ml | source activate ml |
Deep learning, ML research | tensorflow, pytorch, scikit-learn, keras, xgboost, lightgbm, matplotlib, seaborn |
| bio | source activate bio |
Genomics, bioinformatics | biopython, samtools, bcftools, bedtools, fastqc, cutadapt, multiqc, pandas, scikit-bio |
| geo | source activate geo |
GIS, earth science | gdal, rasterio, geopandas, cartopy, xarray, netcdf4, matplotlib, pyproj |
| hpc | source activate hpc |
Parallel/distributed computing | mpi4py, dask, dask-jobqueue, joblib, ipyparallel, numpy, pandas |
All environments include:
-
Python 3.x
-
Mamba for fast package management
- Pip for additional package installation
- Common development tools
Choosing your environment
Select the environment that matches your research domain to get started quickly. You can always install extra packages or create a custom environment based on these templates.
Getting help
- Official documentation: Python documentation and conda documentation and uv documentation
- Built-in help:
python -m pip --help,conda --help, anduv --help - RCC support: contact our Help Desk
- AI assistants: an AI assistant such as Claude can help you interpret errors and adapt the job scripts on this page. See Getting help with AI assistants for what to include in your question and what not to share.