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 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.
- Load the module containing the Python version that you want to use, see the support pages for how to use the module system if you are unfamiliar with it.
- It is advisable to also load any modules that provide any requirements for the python module you are going to install, this includes python-module requirements, like numpy/scipy (from SciPy-bundle) and many others. Using "ml spider python-module-name" will show if there is one installed at all, if there is one but not for the Python version you want to use, ask firstname.lastname@example.org to install it, specifying which module and for which Python version.
- Now you want to create your first virtual environment. Here I call it 'vpyenv', and put it in your 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):
- Load any modules that contain pre-installed dependencies for your software.
- You can also save that set of modules as a collection to make it easy to use the virtual environment later.
- You can now install python modules like this (example, spacy):
pip install --no-cache-dir --no-build-isolation spacy
The module will be downloaded and installed. The "--no-cache-dir" option is required to avoid it from reusing earlier installations from the same user in a different environment. The "--no-build-isolation" is to make sure that it uses the loaded modules from the module system when building any Cython libraries.
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.
- Also load any python-module requirements as per point 3 under "Accessing Virtualenv" above.
- 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: