User Installed Software - Python modules

Installing Python modules

Python modules can usually be installed through python, with the tool 'python', but some module can be difficult, and are easier to install in a stand-alone environment. In these cases we suggest using Virtualenv.

Installing with

Aside from building and installing, you will usually need to set the correct environment before you can use the python module. There may be specifics to building a certain modules (including dependencies or possibly running a configuration script), so you should always check if there is an INSTALL or README file included with the module.

In general, python modules can be installed like this:

  1. Download the python module and untar it.
  2. Load any site modules needed (OpenMPI, Lapack, BLAS...). You should use the gcc-versions if such exist.
  3. cd into the python modules source directory and run:
    python build
  4. Install the python module. It is important that the installation directory is readable from batch jobs. A good choice is to install the python module(s) in $HOME/Public/python-modules, that way they are accessible from batch jobs and are easy to keep track of.
    python install --prefix=<path to your install directory>
  5. Add this line to your ~/.bashrc (change as needed - set to where you have installed the module):

    export PYTHONPATH=$PYTHONPATH:<path to your install directory>/lib/python2.7/site-packages
  6. Check the installation. You need to first open a new shell. Then launch python and type:
    import <python-module>

Installing with Virtualenv

Accessing Virtualenv

  1. Using Virtualenv with HPC2N Python modules
    1. Virtualenv is installed with each of the loadable Python modules and is accessible after the Python module iś loaded. It is highly recommended to use these versions of Virtualenv instead of installing yourself.
    2. OR Download and untar Virtualenv
      1. First you want to get Virtualenv ready to use, if you do not already have. Download it and untar it.
  2. Now you want to create your first virtual environment. Here I call it 'vpyenv', and put it in my Public, but you can call it anything, of course. Create the directory, and run this (from above the Virtualenv directory you just untar'ed, if your are installing Virtualenv yourself):

    python virtualenv-1.10.1/ vpyenv

Installing modules in Virtualenv

  1. In order to install Python modules in the environment, you first need to activate it. Change directory to the environment you created before, and run:
    source bin/activate

    You can deactivate it with

  2. It will now look like this (remember I called my environment 'vpyenv', and put it in my Public directory):
    (vpyenv)t-mn01 [~/Public/vpyenv]$
  3. You can now install python modules like this (example, numpy):
    bin/pip install numpy

    The module will be downloaded and installed.

Updated: 2017-09-21, 11:05