Python

From HPC

(Difference between revisions)
Jump to: navigation, search
(Python)
(Running Task array jobs)
Line 18: Line 18:
  #$ -N ARRAY_TEST_JOB
  #$ -N ARRAY_TEST_JOB
  #$ -cwd -V
  #$ -cwd -V
 +
#$ -q short.q
  #$ -t 1-10
  #$ -t 1-10
   
   
Line 27: Line 28:
  import os
  import os
  os.environ.keys()  
  os.environ.keys()  
-
  taskid = os.environ['JOB_ID']  
+
  taskid = os.environ['JOB_ID']
==Managing packages with virtual environments==
==Managing packages with virtual environments==

Revision as of 12:07, 8 November 2016

Python

Version 2.7 and 3.5 are available on the HPC

Use the following executable binaries to start the correct version

python2
pip2
python3.5
pip3.5

Running Task array jobs

Example SGE job script (One job with 10 tasks)

#!/bin/bash
#$ -N ARRAY_TEST_JOB
#$ -cwd -V
#$ -q short.q
#$ -t 1-10

python2 mycode.py

To use the current SGE job task number your python code you need to access the variable and assign it.

#!/bin/python2
import os
os.environ.keys() 
taskid = os.environ['JOB_ID']

Managing packages with virtual environments

It is recommend to use Python Virtual Environments to create isolated Python environments where you can install any package combinations you need without worrying about dependencies and versions, and indirectly permissions.

Please read | Creating Virtual Environments for more information

The basic usage is like so:

Using virtualenv: (Python 2.6)

virtualenv <DIR>
source <DIR>/bin/activate

Using venv: (Pyhton 3.5)

python3.5 -m venv <DIR>
source <DIR>/bin/activate
Personal tools