Python Tips

To use python on CS Linux servers, you will first need to load either the python or anaconda3 modules. For more information about software modules, see the main article Environment Modules or Available Modules for a list of available software.

Load python3.6 by running:

ktm5j@portal01 ~ $ module load python
ktm5j@portal01 ~ $ which python
/sw/centos/python/current/bin/python       <-- We now have python available

You will not be able to use pip with this installation, unless you use --user flag or a virtualenv. Package install requests can be sent to and are usually installed same day as the request.

If you need to install your own packages virtualenvs may be useful. You can create your own python environment, in which you can install packages via pip. Here is how the process works:

First load the python module and create the env:

ktm5j@portal01 ~/src/pyenvs $ module load python
ktm5j@portal01 ~/src/pyenvs $ virtualenv local-env
Using base prefix '/sw/centos/python/3.6.2'
New python executable in /u/ktm5j/src/pyenvs/local-env/bin/python3.6
Also creating executable in /u/ktm5j/src/pyenvs/local-env/bin/python
Installing setuptools, pip, wheel...done.

Next, unload the python module and source the env activation script:

ktm5j@portal01 ~/src/pyenvs $ module unload python
ktm5j@portal01 ~/src/pyenvs $ source local-env/bin/activate
(local-env) ktm5j@portal01 ~/src/pyenvs $ which python pip
~/src/pyenvs/local-env/bin/pip                     <-- python and pip bins now in env

You are now able to install packages via pip:

(local-env) ktm5j@portal01 ~/src/pyenvs $ pip install fabric
Collecting fabric
  Downloading (51kB)
     |████████████████████████████████| 61kB 3.4MB/s 
Collecting paramiko>=2.4 (from fabric)
  Using cached
Collecting invoke<2.0,>=1.3 (from fabric)
  • linux_python_tips.txt
  • Last modified: 2019/08/08 17:37
  • by ktm5j