Python is a very powerful, easy to use and object-oriented scripting language. The language has numerous packages that are designed for a myriad of different purposes.
Using Python on RCC Resources
Currently Python 2 and Python3 are available on HPC resources (2.7.5 and 3.7.0). Python2 is available by default:
To use Python 3.7.0, load the python3 module:
$ module load python3 $ python3.7
Anaconda is a custom distrubtion of Python with hundreds of modules prepackaged for scientific/mathematic use. For details, refer to our Anaconda documentation. We have two versions of Anaconda installed for python2 and python3 respectively.
To use python 2.7.15 from anaconda, change your PATH environment variable to include
To use python 3.6.5 from anaconda, change your PATH environment variable to include
$ export PATH=/gpfs/research/software/python/anaconda3/bin:$PATH $ which python3 /gpfs/research/software/python/anaconda3/bin/python3
Loading a module within Python is no different than how modules would be loaded on a local installation of Python, e.g.
from math import * or
import math to import the math library. The list of readily available python modules can be found after loading the Python command-line and using
Anaconda and Biopython both contain a wealth of important functions. Anaconda also has a large list of libraries that come with it. Shown below is a list of the major python packages RCC has available that are not contained within Anaconda or Biopython.
To use modules not available on the HPC, either modify the Python-specific environment search path PYTHONPATH to include a directory with the downloaded module, or run the python executable within a directory that includes the downloaded module, both of which are described here.
Custom modules with virtualenv
You can install any Python (v2 or 3) module that you wish using a virtualenv, which is a copy of all Python runtimes and libraries that you can install in your home directory. In fact, you can create multiple virtual environments in your home directory for different applications.
The following example demonstrates how to create Python virtual environment named 'myapp':
# Load Python module $ module load python3 # Create a Python virtualenv named 'myapp' $ virtualenv -p python3.7 ~/myapp # Use pip3 to install pycrypto $ ~/myapp/bin/pip3.7 install pycrypto # Run Python in virtual environment $ ~/myapp/bin/python3.7
If you use pip to install Python packages, you may see warnings during installation that look like:
Failed building wheel for pycrypto
This does not necessarily mean that the package installation failed. You should run Python and test using the module before assuming it is broken.
Below is an example of submitting a Python virtualenv job using Slurm. Notice that the python3.7 executable from the virtualenv is used.
#!/bin/bash #SBATCH -n 1 #SBATCH -p genacc_q #SBATCH -t 00:10:00 #SBATCH --mail-type=ALL module load python3 ~/myapp/bin/python3.7 my_python_script.py