Skip to content

Overview

Several versions of Python are available under module. Those interpreters are bare ones without any extra packages since users can need different versions of the same package for the same version of the interpreter. Users are then invited to install the version they required:

  • either in their home
  • or in a project space if other colleagues want to access them too.

Home installation#

To install a package in your home (~/.local/lib/python<version number>/site-packages/),

  1. select the version of Python you want

Code Block (bash)

$ module av Python
-------------------- /local/gensoft2/devmodules ---------------------
Python/2.7.11 Python/2.7.8  Python/3.4.1  Python/3.6.0  Python/3.7.2
$ module load Python/<version>
  1. use the pip command corresponding to the chosen Python version (pip2 or pip3) with --user option:

Code Block (bash)

$ pip<major number version>  install --user  <required package>

the module will be installed in ~/.local/lib/python<version number>/site-packages/ which is part of the standard search PATH. So python will be able to find it as any standard module.

Installation in a project space#

If you want to make the package accessible to other members of your unit or project, you can install the package in a sub-directory of the project space. The install commands become

  1. select the version of Python you want

Code Block (bash)

$ module av Python
-------------------- /local/gensoft2/devmodules ---------------------
Python/2.7.11 Python/2.7.8  Python/3.4.1  Python/3.6.0  Python/3.7.2
$ module load Python/<version>
  1. use the pip command corresponding to the chosen Python version (pip2 or pip3):

  2. either with --target option to install the package in /path/to/the/chosen/subdirectory/<package name-version>-py<.Python version>.egg-info/ and /path/to/the/chosen/subdirectory/<package name>

Code Block (bash)

$ pip<major number version>  install  --target /path/to/the/chosen/subdirectory  <required package>
  1. or with --prefix option to install in a canonical tree view /path/to/the/chosen/subdirectory/lib/python<version>/site-packages

Code Block (bash)

$ pip<major number version>  install  --prefix /path/to/the/chosen/subdirectory  <required package>

Note that when installed on a directory that is not part of the standard python search PATH, you must

    1. either set the environnement PYTHONPATH to point to this directory

Code Block (bash)

PYTHONPATH=/path/to/the/chosen/subdirectory/lib/python<version>/site-packages:$PYTHONPATH
  1. or in your code point python to use this directory in his search path, eg:

Code Block (py)

#! /usr/bin/env python3
import sys
#let say we are using python/3.6.0
sys.path.insert(0, 'path/to/the/chosen/subdirectory/lib/python3.6/site-packages')

import XYZ # where XYZ is the newliy install module

Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.

false5FAQAfalsemodifiedtruepagelabel in ("installation","python","pip") and type = "page" and space = "FAQA"python pip installation

true

Related issues