Skip to main content Skip to navigation
Kamiak Programmer's Guide

Running Python

Versions of Python

There are several versions of Python available on Kamiak. By default the operating system provides Python versions 2.7.5 and 3.4.5. Other versions can be loaded using environment modules. The module versions of Python were compiled with the –enable-shared option which can impact performance of various operations. As such you may wish to compile your own build more fine tuned to your workload.

Python vs. Anaconda

The Python environment modules available on Kamiak generally provide only the Python binaries, standard library, and pip. If you would like to use additional scientific Python libraries (SciPy, NumPy,etc.) you can switch to Anaconda. Anaconda is also available as modules (run module avail anaconda) and provides not just Python but also all the Anaconda bundled packages.

Installing Python Modules

Very often Python programmers need to install additional modules, such as those on PyPI. On Kamiak you do not have access to install modules into system locations as you can on your own laptop or similar. However, Python provides an easy way to allow you to install modules you need into your home directory or other storage. This allows you to install any version of any module you want, without impacting other users.

Using pip (PEP 370)

Installing a Python package with pip is simple:

$ module load python3

$ pip install --user quadpy
Collecting quadpy
  Downloading quadpy-0.9.0-py2.py3-none-any.whl (306kB)
    100% |████████████████████████████████| 307kB 812kB/s
Installing collected packages: quadpy
Successfully installed quadpy-0.9.0

$ python3
Python 3.5.0 (default, Jun 20 2017, 16:07:03) 
[GCC 6.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import quadpy                                                                                                                                                                                                                  
>>>

The package will be installed into your home directory (in this case) at .local/lib/python3.5/site-packages with any binaries in .local/bin.

Installing Anaconda Modules

Conda Environments

Anaconda can create local environments using the conda command. Let’s create a conda environment named “md” to house the package we need for RASPA2. To create an environment named “md” with python 2.7 run

conda create -n md python=2.7

Now, let’s add the SciPy package from the Anaconda repository to our md environment. In this case won’t specify the version.

conda install -n md scipy

The RASPA2 package isn’t available from the Anaconda repository, but can be installed using pip. First, activate the md environment

source activate md

Then install the raspa2 package using pip

pip install raspa2

You can now run rapsa2 from within the md environment. When you’re done using raspa2 you can deactivate the md environment and return to the base anaconda install.

source deactivate

Lastly, if you ever want to delete the md environment run

conda remove -n md --all
From Source

To install as a user from source, you need only add the ––user flag to the usual install command. As an example, let’s install the StochPy package to our home directory. First, download the package and unpack it in your home directory. Next load the appropriate python module to satisfy your packages dependencies. StochPy requires numpy, so we’ll use the anaconda2 module. We can then make a local installation of StochPy using the python setup.py install ––user command. Lastly we can check that our installation was successful by invoking python -c “import stochpy”

[ ~]$ module load anaconda2
[ ~]$ unzip StochPy-2.3.zip
[ ~]$ cd StochPy-2.3
[ StochPy-2.3]$ python setup.py install --user
/opt/apps/anaconda2/2.4.0/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
 warnings.warn(msg)
running install
running build
.
.
.
byte-compiling /home/nick.maggio/.local/lib/python2.7/site-packages/stochpy/tools/__init__.py to __init__.pyc
byte-compiling /home/nick.maggio/.local/lib/python2.7/site-packages/stochpy/tools/kSolver.py to kSolver.pyc
running install_egg_info
Writing /home/nick.maggio/.local/lib/python2.7/site-packages/StochPy-2.3-py2.7.egg-info
running install_clib
[ StochPy-2.3]$ python -c "import stochpy"
Info: Model dsmts-003-03.xml.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-001-11.xml copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-003-04.xml copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model ImmigrationDeath.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-001-19.xml copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model GeneDuplication.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model CellDivision.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-003-04.xml.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model Autoreg.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model Burstmodel.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model chain1500.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-002-10.xml.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model chain5.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model chain500.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model Schlogl.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model Signaling3cCD.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-001-01.xml.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model DecayingDimerizing.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-001-11.xml.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model Isomerization.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-001-01.xml copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model SignalingTimeVaryingL.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model BirthDeath.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-001-19.xml.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-002-10.xml copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model Autoreg.xml copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model Polymerase.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model TranscriptionIntermediate.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model chain50.psc copied to /home/wsu.NID/Stochpy/pscmodels
Info: Model dsmts-003-03.xml copied to /home/wsu.NID/Stochpy/pscmodels
#######################################################################
# #
# Welcome to the interactive StochPy environment #
# #
#######################################################################
# StochPy: Stochastic modeling in Python #
# http://stochpy.sourceforge.net #
# Copyright(C) T.R Maarleveld, B.G. Olivier, F.J Bruggeman 2010-2015 #
# DOI: 10.1371/journal.pone.0079345 #
# Email: tmd200@users.sourceforge.net #
# VU University, Amsterdam, Netherlands #
# Centrum Wiskunde Informatica, Amsterdam, Netherlands #
# StochPy is distributed under the BSD licence. #
#######################################################################
Version 2.3.0
Output Directory: /home/wsu.NID/Stochpy
Model Directory: /home/wsu.NID/Stochpy/pscmodels
[~ StochPy-2.3]$

Note: that the ––user flag directs python to install the package off your home directory. If you would like your packages to be installed to a different directory use the ––prefix flag.