Using Python and Pip with Environment Modules

Body

Several versions of Python are available using Environment Modules, in addition to the default package versions. You can determine what version is available by appending the --version switch to your python command.

NOTE: For AI.Panther users, the python3 command is only supported.

Example (version numbers will be different on each system):

  • List current modules.
    ~ $ module list
    
    No Modulefiles Currently Loaded.
  • Show current Python3 versions. Since no Python modules are loaded, they are the OS provided versions.
     ~ $ python3 --version
    
     Python 3.5.1 
  • List available Python modules. Default module is indicated with (default).
     ~ $ module avail python
    
     ------------------------- /opt/software/modules/ --------------------------
    
     python/3.4.2 python/3.5.1(default) 
  • Load default Python module.
     ~ $ module load python
  • Show Python and Python3 versions. Since only the Python 3.5.1 module was loaded, it was the only version that changed.
     ~ $ python3 --version
    
     Python 3.5.1 
  • Unload Python module.
     ~ $ module unload python

Pip with Environment Modules

Pip can also be used with python to install python packages.

As with Python, pip has different commands for different versions:

  • pippip2, and pip2.7 are not supported and do not use.
  • pip3 - to install OS maintained Python 3 pip packages.

Pip examples (version numbers will be different on each system):

  • List current modules.
     ~ $ module list
    
     No Modulefiles Currently Loaded. 
  • Display pip3 version. With no Python modules loaded, they use the OS provided version.
     ~ $ pip3 --version
    
     pip 9.0.1 from /usr/lib/python3.4/site-packages (python 3.4) 
  • Load Python 3.4.2 specific module.
     ~ $ module load python/3.4.2
  • Display pip3 versions. Now they show the version from the loaded Python 3.4.2 module.
     ~ $ pip3 --version
    
     pip 9.0.1 from /opt/software/python/python-3.4.2/lib/python3.4/site-packages (python 3.4)
  • Unload Python 3.4.2
     ~ $ module unload python/3.4.2
  • Load the default python module, which currently is Python 3.5.1.
     ~ $ module load python
  • Display the pip3 versions. Now they show the version from the loaded 3.5.1 Python module.
     ~ $ pip3 --version
    
     pip 9.0.1 from /opt/software/python/python-3.5.1/lib/python3.5/site-packages (python 3.5)
    

Installing a pip module into your userspace

NOTE: Be sure to specify the version of Pip you want to use.

 ~ $ pip3 install --user <pip_module>

 Collecting <pip_module>

   Downloading <pip_module>.whl (43.1MB)

     100% |████████████████████████████████| 43.1MB 12kB/s 

Details

Details

Article ID: 3282
Created
Thu 2/2/23 1:57 PM
Modified
Thu 8/15/24 1:17 PM