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.5.1). Python2 is available by default:
To use Python 3.5.1, load the python3 module:
$ module load python3 $ python3
Anaconda is a custom distrubtion of Python2.7 with hundreds of modules prepackaged for scientific/mathematic use. For details, refer to our Anaconda documentation.
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
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 ~/myapp # Use pip3 to install pycrypto $ ~/myapp/bin/pip3.5 install pycrypto # Run Python in virtual environment $ ~/myapp/bin/python3.5
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.5 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.5 my_python_script.py