User Installed Software - Python modules
Installing Python modules
Python modules can usually be installed through python, with the tool 'python setup.py', 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 setup.py
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:
- Download the python module and untar it.
- Load any site modules needed (OpenMPI, Lapack, BLAS...). You should use the gcc-versions if such exist.
- cd into the python modules source directory and run:
python setup.py build
- 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 setup.py install --prefix=<path to your install directory>
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
- Check the installation. You need to first open a new shell. Then launch python and type:
Installing with Virtualenv
- Using Virtualenv with HPC2N Python modules
- Virtualenv is installed with each of the loadable Python modules and is accessible after the Python module is loaded. It is highly recommended to use these versions of Virtualenv instead of installing yourself.
- 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. Run the following to initialize the environment:
virtualenv --system-site-packages $HOME/Public/vpyenv
Installing modules in Virtualenv
- 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:
You can deactivate it with
- It will now look like this (remember I called my environment 'vpyenv', and put it in my Public directory):
- You can now install python modules like this (example, spacy):
pip install spacy
The module will be downloaded and installed.