Difference between revisions of "Applications/Python"
From HPC
(→Virtual Environments) |
(→Virtual Environments) |
||
Line 71: | Line 71: | ||
* An arbitrary number of virtual environments can be created for different tasks | * An arbitrary number of virtual environments can be created for different tasks | ||
* Reproducibility - A user can replicate a python environment on any system, so as to be able to run or re-run a particular task or job under the same conditions | * Reproducibility - A user can replicate a python environment on any system, so as to be able to run or re-run a particular task or job under the same conditions | ||
+ | |||
+ | '''Creation of Virtual Environment Using Python 2.7.11 or 3.5.1 on Viper''' | ||
+ | |||
+ | To create a virtual environment you would issue the following command: | ||
== Further Information == | == Further Information == |
Revision as of 16:38, 27 February 2018
Contents
Application Details
- Description: Python is a high-level interpreted programming language for general-purpose programming, supported by a large number of libraries for many tasks
- Versions: Python 2.7.11 and 3.5.1
- Module names: python/2.7.11 python/3.5.1
- License: Free to use - Python Software Foundation License
Usage Examples
Python is provided by the Anaconda package too
Interactive
Interactive with command line:
[username@c170 ~]$ module add python/anaconda/4.0/2.7 [username@c170 ~]$ python Python 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
Interactive with command line with IPython:
[username@c170 ~]$ ipython Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15) Type "copyright", "credits" or "license" for more information. IPython 5.1.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]:
Batch Submission
#!/bin/bash #SBATCH -J PythonTest # Job name, you can change it to whatever you want #SBATCH -N 1 # Number of nodes #SBATCH --ntasks-per-node 1 # Number of cores per node #SBATCH -o %N.%j.out # Standard output will be written here #SBATCH -e %N.%j.err # Standard error will be written here #SBATCH -p compute # Slurm partition, where you want the job to be queued module purge module add python/3.5.1 python PythonTest.py
This is then submitted as follows:
[username@login01 ~]$ sbatch Pythontest.job Submitted batch job 289522
Virtual Environments
A Python Virtual Environment allows users to create a custom environment/s in which they can have the packages, and versions of said packages that they require without having to have elevated user privileges on the system.
There are many benefits to using a virtual environment on a system. Here is a short non-exhaustive list of a few of the key benefits:
- Control over packages and package versions
- An arbitrary number of virtual environments can be created for different tasks
- Reproducibility - A user can replicate a python environment on any system, so as to be able to run or re-run a particular task or job under the same conditions
Creation of Virtual Environment Using Python 2.7.11 or 3.5.1 on Viper
To create a virtual environment you would issue the following command: