Python is an integrated technical computing environment that combines sophisticated computation, advanced graphics and visualization, and a high-level programming language.
ARCS offers a free 10-part video series called Python for Scientists & Engineers. Click here to start learning Python.
Python on Rivanna
The default Python is required for system purposes and is generally too old for applications. Python is offered as Python 2.7 or 3.3 with basic external packages installed. We offer Python through the Anaconda distribution from Continuum Analytics. Anaconda bundles a large number of popular modules and packages, as well as the Spyder IDE, an iPython console, and Jupyter notebooks. To see all available versions, run
module spider anaconda
Two versions are available, currently
anaconda/5.2.0-py2.7 (Python 2.7.14) and
anaconda/5.2.0-py3.6 (Python 3.6). You must specify the full version and suffix of the module to obtain the Python version you wish to use.
For example, to load the
anaconda/5.2.0-py2.7 module which sets up your environment to use the Python 2.7 interpreter, run this command:
module load anaconda/5.2.0-py2.7
View list of all installed packages
After loading an anconda module, a list of all installed packages can be viewed by running this command:
Package installation with pip
pip install --user yourpackage
The --user option will install it into your home directory. It is bound to a particular version and will have to be reinstalled if Anaconda is upgraded.
Package installation with conda
Certain Python packages are available pre-bundled via public Conda channels. Conda packages are installed in environments, i.e. specific directories. This is useful to isolate incompatible packages so that they do not conflict with each other. Only one Conda environment can be active at any given time. The Anaconda distribution provides a root environment that contains all of the preinstalled Anaconda packages. In addition, users can create their own Conda environments in their home directory.
Use one of the following two commands to install a particular package provided via a specific Conda channel in your own custom environment.
For example, if you want to install the epic package into a new environment named custom_env that does not exist yet, run this command:
module load anaconda/5.2.0-py3.6 conda create -n custom_env -c bioconda epic
To install the same package into an existing environment, run:
conda install -n custom_env -c bioconda epic
-n custom_env: Specifies the name of the environment where the package(s) will be installed.
-c bioconda: Specifies that the packages to be installed are provided by the bioconda channel.
epic: The name of the Conda package to be installed. Multiple packages separated by whitespaces can be listed.
The user environments are installed under ~/.conda/envs.
Using Conda environments
After loading an anaconda module on Rivanna, the root environment with default packages is activated. To list all environments, run this command:
conda env list
To use packages in your own environment named custom_env, run this command:
source activate custom_env
To switch back to the default root environment, run this command:
source deactivate custom_env
Sample SLURM script
#!/bin/bash #SBATCH -n 1 #SBATCH -t 01:00:00 #SBATCH -o myprog.out #SBATCH -p standard #SBATCH -A mygroup module purge module load anaconda/5.2.0-py3.6 # or anaconda/5.2.0-py2.7 # optional: uncomment next line to use your custom Conda environment; replace 'custom_env' with actual env name # source activate custom_env python myscript.py