Python is an interpreted high-level programming language for general-purpose programming. Python has had many versions over the years. Most python programs run on Python 2 (example - 2.7.x) or Python 3 (example - 3.5.x).
Modules and Versions
To check the available Python modules on a cluster. Please type the following command.
[NetID@cluster NetID]$ module spider Python
This will show many version of python complied with different toolchains. The first part of the module name (Ex - Python/3.5.1) refers to the python language version. The second part of the module name (Ex - -intel-2016a) refers to the HPRC toolchain used to compile the module.
Python/3.5.1-intel-2016a Python/3.5.2-foss-2017A Python/3.5.2-GCCcore-6.3.0-bare Python/3.5.2-intel-2016a Python/3.5.2-intel-2016b Python/3.5.2-intel-2017A Python/3.5.2-iomkl-2017A
What is a toolchain?
A toolchain on a TAMU HPRC cluster is a collection of tools used for building software. They typically include:
- a compiler collection providing basic language support (C/Fortran/C++)
- a MPI implementation for multi-node communication
- a set of linear algebra libraries (FFTW/BLAS/LAPACK) for accelerated math
For more information on toolchains checkout our Toolchains page.
Which Python to use ?
If your project requires a specific version of python language (Ex. 2.7.11) with specific compiler than use that particular version. We recommend using the most recent toolchain (intel-2017A) with your python version. Once you decide your version than please continue to do your work on the same version. Changing versions everytime can cause errors. In short, current recommended version for python 2 language
Current recommended version for python 3 language
You can use "module load" command for loading a particular python version on cluster. An example command for loading python 3 :
[NetID@cluster NetID]$ module load Python/3.5.2-intel-2017A
You can use the following example command for unloading python 3.
[NetID@cluster NetID]$ module purge Python/3.5.2-intel-2017A
Write the following command, if you want to check the python language version that you are currently using.
[NetID@cluster NetID]$ python --version
Default Python Packages (pip)
Python is useful if it has many packages. The "pip list" command will show the default python packages available.
[NetID@cluster NetID]$ pip list
NOTE: Users don't have permission to install new packages using "pip install" command directly on the terminal. Users need to create a virtual environment for that purpose.
How to install new packages (pip install) ?
Users first need to create a private virtual environment and install packages in that environment.
Create a virtual environment
Users should create virtual environment inside "scratch" and preferably inside their project directory. The next few commands show how to create a virtual environment inside a new project directory.
[NetID@cluster NetID]$ module load Python/3.5.2-intel-2017A # Load Python module [NetID@cluster NetID]$ cd $SCRATCH # Go to scratch directory [NetID@cluster NetID]$ mkdir python_project # Make a new directory named python_project [NetID@cluster NetID]$ cd python_project # Go to the project directory [NetID@cluster python_project]$ virtualenv venv # Make a virtual environment "venv"
Activate/Deactivate virtual environment
This section shows how to activate and deactivate the virtual environment. You have to give path from your project directory
[NetID@cluster NetID]$ cd $SCRATCH/python_project # Go to the project directory [NetID@cluster python_project]$ source venv/bin/activate # Activate virtual environment (Command line should show environment name on left) (venv) [NetID@cluster python_project]$ pip list # Check the packages in environment (venv) [NetID@cluster python_project]$ python --version # Check the python version in environment (venv) [NetID@cluster python_project]$ deactivate # Deactivate virtual environment [NetID@cluster python_project]$ # Command line returns to normal