Site Tools


Action disabled: index
linux_python_tips

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 cshelpdesk@virginia.edu and are usually installed same day as the request.

Virtualenvs

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/python
~/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 https://files.pythonhosted.org/packages/d7/cb/47feeb00dae857f0fbd1153a61e902e54ed77ccdc578b371a514a3959a19/fabric-2.5.0-py2.py3-none-any.whl (51kB)
     |████████████████████████████████| 61kB 3.4MB/s 
Collecting paramiko>=2.4 (from fabric)
  Using cached https://files.pythonhosted.org/packages/4b/80/74dace9e48b0ef923633dfb5e48798f58a168e4734bca8ecfaf839ba051a/paramiko-2.6.0-py2.py3-none-any.whl
Collecting invoke<2.0,>=1.3 (from fabric)
...
linux_python_tips.txt · Last modified: 2023/08/29 19:56 by 127.0.0.1