Zentrum für Datenverarbeitung (ZDV) (data center)

Installing Python packages on BinAC

This tutorial describes how to install Python packages in your $HOME directory on BinAC via Miniconda, which can be used to create reproducible runtime environments. Miniconda can manage packets, dependencies and environments for every language, not just Python.

First of all, Miniconda has to be installed in $HOME and the working environment has to be configured.

Installing Miniconda

We install Miniconda by downloading and running the installer from their website.

Miniconda will be added to your $PATH during the installation if you don't deny it. This means that, by default, the Python and Pip executables shipped by Miniconda will be executed instead of the system wide installed ones. Make sure to set this option according to your preferences. All the other options can be left in their default state.

$ wget repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
$ sh Miniconda3-latest-Linux-x86_64.sh

Sollen neben Python-Paketen auch Conda-Pakete installiert werden, muss noch zusätzlich der bioconda conda-channel hinzugefügt werden (relevant für Bioinformatiker).

If you want to install Conda packages alongside Python packages you have to add the bioconda channel as well (mostly relevant for bioinformatics).

$ conda config --add channels defaults
$ conda config --add channels bioconda
$ conda config --add channels conda-forge

Configuring Conda environment

Ein Beispiel der neuen Umgebung 'test' mit einer frischen Python 3.5 Installation:

In order install packages using Conda, a new environment has to be created first. This will install a new Python installation with some basic packets in the specified directory.

$ conda create --name test python=3.5

The environment has been created in $HOME but it has to be activated before installing new packages. This basically configures the current shell to use the Python executables of that specific environment.

$ source activate test

Using which we can confirm that the correct executable is being used.

$ which python

    ~/miniconda3/envs/test/bin/python

Installing new packages

Installing new packages via pip install is very easy. Conda is making sure that all files get put into the correct directory once the environment has been activated. For example, installing a specific Numpy version works like this:

$ pip install numpy==1.15.4

You can check the Numpy version and it's installation directory in a Python shell.

$ python

>>> import numpy
>>> numpy.__version__
'1.15.4'
>>> numpy.__path__
['~/miniconda3/envs/test/lib/python3.5/site-packages/numpy']

Listing and removing Conda environments

Existing Conda environments can be listed using

$ conda env list

and a specific environment can be fully removed using

$ conda remove --name test --all

Additional resources

As mentionded, Conda can do a lot more than managing Python packets. Learn more in Conda's User guide.