Python

The scripting language Python is installed on all the interactive and computing platform at Computing Center. You can find more information about Python on the official site or by typing:

% man python
% python -h

You have the possibility to use Python in a script file. In this case, it is better to use the .py suffix. Your file should contain as the first line:

#!/usr/bin/env python

Your file should also have the “executable” Unix characteristic because Python is an interpreted language. You should not generated an binary executable in the sense of programming languages as C, C++ or Fortran.

Note

Different releases are available at CC-IN2P3. Please follow the software loader syntax to list and activate the required release.

Please also consider the tips on custom-installations.

To go even further, you can refer to the documents used during the trainings provided by the CC-IN2P3.

Virtual environment

You have also the option of installing locally the python packages you need without administrator rights on the servers. To do so you will need to load a release following Python 3.3 (venv is only available from version 3.3) and follow the procedure below:

% python -m venv --system-site-packages "my_new_env"
% source "my_new_env"/bin/activate
(my_new_env) % python -m pip install --user my_module

or by specfiying the path:

(my_new_env) % python -m pip install --prefix /path/to/my_module
  • The first command is used to create an “environment” from the given directory my_new_env, the directory in which the new Python packages will be installed and configured.

  • The following command tells the system to use this environment.

  • The last command requests Python via the pip module to install the new module my_module.

Official documentation:

You can then see the installed package:

(my_new_env) % pip list | grep my_module
(my_new_env) % pip show my_module

To exit the virtual environment, run the command:

(my_new_env) % deactivate