Python

From HPC

(Difference between revisions)
Jump to: navigation, search
(Python)
Line 1: Line 1:
=Python=
=Python=
-
Version 2.7 and 3.5 are available on the HPC
+
==Managing packages with virtual environments==
-
Use the following executable binaries to start the correct version
+
==PyEnv==
-
python2
+
[https://github.com/pyenv/pyenv]
-
pip2
+
 
-
   
+
pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.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.
-
For example
+
 
-
pip2 install --user package_name
+
===pyenv-virtualenv===
 +
 
 +
[https://github.com/pyenv/pyenv-virtualenv]
 +
 
 +
pyenv-virtualenv is a pyenv plugin that provides features to manage virtualenvs and conda environments for Python on UNIX-like systems.
 +
 
 +
==Anaconda/Conda/Miniconda==
 +
 
 +
[https://docs.conda.io/en/latest/]
 +
 
 +
Package, dependency and environment management for any language---Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN
 +
 
 +
Conda is an open source package management system and environment management system that runs on Windows, macOS, and Linux. Conda quickly installs, runs and updates packages and their dependencies. Conda easily creates, saves, loads, and switches between environments on your local computer. It was created for Python programs but it can package and distribute software for any language.
 +
 
 +
See also [[Conda (R/Python package management)]]
-
python3.5
 
-
pip3.5
 
-
 
-
For example
 
-
pip3.5 install --user package_name
 
==Running Task array jobs==
==Running Task array jobs==
Line 28: Line 37:
  #$ -t 1-10
  #$ -t 1-10
   
   
-
  python2 mycode.py
+
  python mycode.py
To use the current SGE job task number your python code you need to access the variable and assign it.
To use the current SGE job task number your python code you need to access the variable and assign it.
-
  #!/bin/python2
+
  #!/bin/python
  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==
 
-
 
-
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 [https://packaging.python.org/installing/#creating-virtual-environments | 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
 

Revision as of 10:14, 24 September 2019

Contents

Python

Managing packages with virtual environments

PyEnv

[1]

pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.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.

pyenv-virtualenv

[2]

pyenv-virtualenv is a pyenv plugin that provides features to manage virtualenvs and conda environments for Python on UNIX-like systems.

Anaconda/Conda/Miniconda

[3]

Package, dependency and environment management for any language---Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN

Conda is an open source package management system and environment management system that runs on Windows, macOS, and Linux. Conda quickly installs, runs and updates packages and their dependencies. Conda easily creates, saves, loads, and switches between environments on your local computer. It was created for Python programs but it can package and distribute software for any language.

See also Conda (R/Python package management)


Running Task array jobs

Example SGE job script (One job with 10 tasks)

#!/bin/bash
#$ -N ARRAY_TEST_JOB
#$ -cwd -V
#$ -q short.q
#$ -l mem_free=1G,h_vmem=1.2G
#$ -t 1-10

python mycode.py

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

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