Skip to content

Installing Python packages

about 8 minutesStudents, Staffchecked 24 August 2026

Over the past decade, the Python programming language and Scientific Python packages like NumPy, SciPy, JAX, and PyTorch have gained a lot of popularity in the data science and HPC communities.

A Python installation usually consists of the Python interpreter, the Python standard library and one or more third party Python packages. Such Python packages may include both compiled code and a lot of so-called Python modules, i.e. a lot of small files containing Python code. A typical Conda environment tends to contain tens to hundreds of thousands of relatively small files filling up your file quota. Additionally, installing such a large number of small files to our storage can put a lot of strain on the filesystem and can lead to suboptimal cluster performance.

Conda is an open source environment and package management system. With Conda you can create independent environments, where you can install applications such as python and R, together with any packages which will be used by these applications. The environments are independent, with the Conda package manager managing the binaries, resolving dependencies, and ensuring that package used in multiple environments are stored only once. In a typical setting, each user has their own installation of a Conda and a set of personal environments.

Conda channels are the locations where packages are stored. There are also multiple channels, with some important channels being:

  • defaults, the default channel,
  • anaconda, a mirror of the default channel,
  • bioconda, a distribution of bioinformatics software, and
  • conda-forge, a community-led collection of recipes, build infrastructure, and distributions for the conda package manager.

The most useful channel that comes pre-installed in all distributions, is Conda-Forge. Channels are usually hosted in the official Anaconda page, but in some rare occasions custom channels may be used. For instance the default channel is hosted independently from the official Anaconda page. Many channels also maintain web pages with documentation both for their usage and for packages they distribute:

The Anaconda3 distribution is provided as a module on UBELIX. To use any conda commands, load the module using

bash
module load Anaconda3

When using conda the system may complain about:

bash
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.

Please do not run conda init. Instead initialise the conda environment using:

bash
module load Anaconda3
eval "$(conda shell.bash hook)"

This should also be used in your batch submission scripts when working with conda environments.

As an example, the creation and use of an environment for pandas jobs is presented. The command,

bash
conda create --name pandas

creates an environment named pandas. The environment is activated with the command

bash
conda activate pandas

anywhere in the file system.

Next, install the base R environment package that contains the R program, and any R packages required by the project. To install packages, first ensure that the pandas environment is active, and then install any package with the command

bash
conda install <package_name>

all the required packages. Quite often, the channel name must also be specified:

bash
conda install --channel <channel_name> <package_name>

Packages can be found by searching the conda-forge channel.

bash
conda install --channel conda-forge pandas

will install all the components required to use the pandas pacakge in Python. After all the required packages have been installed, the environment is ready for use.

Packages in the conda-forge channel come with instructions for their installation. Quite often the channel is specified in the installation instructions, -c conda-forge or --channel conda-forge.

After work in an environment is complete, deactivate the environment,

bash
conda deactivate

to ensure that it does not interfere with any other operations. In contrast to modules, Conda is designed to operate with a single environment active at a time. Create one environment for each project, and Conda will ensure that any package that is shared between multiple environments is installed once.

Since all computationally heavy operations must be performed in compute nodes, Conda environments are also used in jobs submitted to the queuing system. Returning to the pandas example, a submission script running a single core pandas job can use the pandas environment as follows:

#SBATCH --job-name pandas-test-job
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=1
#SBATCH --time=0-02:00:00
#SBATCH --account=gratis
echo "Launched at $(date)"
echo "Job ID: ${SLURM_JOBID}"
echo "Node list: ${SLURM_NODELIST}"
echo "Submit dir.: ${SLURM_SUBMIT_DIR}"
echo "Numb. of cores: ${SLURM_CPUS_PER_TASK}"
module load Anaconda3
eval "$(conda shell.bash hook)"
conda activate pandas
python pandas_test.py
conda deactivate

The Conda environment managers download and store a sizable amount of data to provided packages to the various environments. Even though the package data are shared between the various environments, they still consume space in your or your project’s account.

There are two main sources of unused data, the compressed archives of the packages that Conda stores in its cache when downloading a package, and the data of removed packages. All unused data can be removed with the command

bash
conda clean --all

that opens up an interactive dialogue with details about the operations performed. You can follow the default option, unless you have manually edited any files in you package data directory (default location ${HOME}/conda).

Sources

In some cases Python packages are not avaible through the conda channels and need to be installed through pip. In this case simply ensure that pip is indeed set to the pip executable within the environment

bash
which pip
~/.conda/envs/<env name>/bin/pip

For instance, assume that a mkdocs project requires the following packages:

  • mkdocs
  • mkdocs-minify-plugin

The package mkdocs-minify-plugin is less popular and thus is is not available though a Conda channel, but it is available in PyPI. Activate your conda environment and install the required packages with pip

bash
pip install --upgrade mkdocs mkdocs-minify-plugin

inside the environment. The packages will be installed inside a directory that conda created for the Conda environment, for instance

${HOME}/conda/envs/mkdocs

along side packages installed by conda. As a results, ‘system-wide’ installations with pip inside a Conda environment do not interfere with system packages.

Virtualenv is the Pythons native way of isolating a particular python environment from the default one. Each environment resides in a self-contained directory, so multiple virtualenvs can co-exist side by side with different versions of tools or dependencies installed. The downside of this approach is that the Python version can’t be changed. If you need to be able to run specific versions of Python, please use the Conda installation method.

We can create a virtualenv:

bash
python -m venv --system-site-packages venvs/venv-for-demo

or

bash
virtualenv --system-site-packages venvs/venv-for-demo

We recommend that, as in the example above, to use the --system-site-packages option. This ensures that already installed packages are used.

To use a virtualenv it is necessary to activate it:

bash
source venvs/venv-for-demo/bin/activate
(venv-for-demo) [user@cluster:~]$

Once activated the prompt changes and any Python related commands that follow will refer to the Python installation and packages contained/linked in the virtualenv.

To install packages in the virtualenv it needs to be activated, and while it is active any packages installed with pip will be actually installed inside the virtualenv itself:

bash
source venvs/venv-for-demo/bin/activate
(venv-for-demo) [user@cluster:~]$ pip install biopython

To stop using a virtualenv one needs to deactivate it:

bash
(venv-for-demo) [user@cluster:~]$ deactivate
[user@cluster:~]$

To permanently remove a virtualenv one simply deletes the directory which contains it.

bash
rm -rf venvs/venv-for-demo/

We strongly discourage installing Python packages directly through the OS Python with pip without using virtual environments as described above.