Python Env

What is Python?

Python is a programming language that lets you work quickly and integrate systems more effectively.

What Python version/environment can users find/set up on ENEAGRID/CRESCO?

On HPC clusters the default system Python is already available:

System

Python version

CRESCO8

3.9.18

CRESCO7

3.9.16

XCRESCO

3.9.16

CRESCO6

2.7.5

To check the Python version use the command

python -V

Note

If the user needs a different version of Python, you can load the Scipy module can be loaded by using the module command.

How to create a local Python environment by virtualenv tool

If the user needs to create a local environment where it is possible to install all Python modules required for a particular software, the virtualenv tool (already installed on CRESCO) can be useful.

Using virtualenv, the user can generate and configure a local Python environment, also specifying the destination directory, such as a subfolder of the user home, in which all the necessary modules/packages can be installed.

Note

The CRESCO6 user does not have to install virtualenv as described in many tutorials, because it is already available. It is only necessary to load the scipy or scipy39 modules.

For example:

Create a subfolder in the user home, move into it and generate a local virtual environment named myenv by using virtualenv:

mkdir myLocalPython
cd myLocalPython/
python3 -m venv myenv

Check that the environment has been created:

>ls
myenv

Activate the local environment:

source myenv/bin/activate

The myenv label in parentheses, before the username and hostname, indicates that the environment is active.

Then use local python and pip to install packages. For example, install the pandas package through a requirements.txt file:

>which python
~/myLocalPython/myenv/bin/python

>which pip
~/myLocalPython/myenv/bin/pip

>echo "pandas" > requirements.txt
>ls
>myenv requirements.txt

>cat requirements.txt
pandas

>pip install -r requirements.txt

Collecting pandas
Downloading pandas-1.1.3-cp36-cp36m-manylinux1_x86_64.whl (9.5 MB)
...
Successfully installed numpy-1.19.2 pandas-1.1.3 python-dateutil-2.8.1 pytz-2020.1 six-1.15.0

To deactivate the virtual environment, use:

deactivate

The myenv label in parentheses disappears when the environment is no longer active.