Unsorted Notes

Customizing centrally installed Python distributions 2

Even comprehensive installations require sometimes individual extensions. Part 2.

Yesterday's post discussed virtual environments and how I can use them with Canopy. Today has Anaconda the floor.

Customizing Anaconda

The new environment can be created with a few commands.

1. Preparation of the directory for the environment:

$ MY_ENV_ROOT=/cfs/klemming/nobackup/m/michs/pydevel
$ mkdir -p $MY_ENV_ROOT

2. Now, the virtual environment that should be used in the future will be created:

$ module load anaconda/py27/1.8
$ conda create -p $MY_ENV_ROOT/at1 anaconda

The command module load provides access to the central installation of Anaconda.

The virtual environment will be created by the command conda create. The option -p specifies the path to the new environment. The last argument is the name of the meta-package anaconda, which should be installed into the new environment. In that way I will get access to all packages referenced by anaconda also in the new environment.

3. Activation of the new environment:

$ module load anaconda/py27/1.8
$ source activate $MY_ENV_ROOT/at1
(at1) $ python
Python 2.7.5 |Anaconda 1.8.0 (64-bit)| (default, Nov  4 2013, 15:30:26)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(at1) $ source deactivate

In order to use the python installation of the new environment, one has to load the originally used module in order to get access to the root environment and to source the activate script with the path to the virtual environment as argument. Switching back to the default system environment could be done by sourcing the the deactivate command.

Now again, own packages can be installed into this environment using distutils, easy_setup, or pip. This will work automatically as long as the environment has been activated. Otherwise, the pathes have to be specified as in usual installation activities. Any other setup method will work too of course.


2013-12-31 – Category: programming – Tags: python