Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
working_with_python [2018/08/30 07:49] – [Bypassing the existing python environment] lenocil | working_with_python [2019/04/23 13:25] – jansen |
---|
====== Working with Python ====== | ====== Working with Python ====== |
Python is available on all Sterrewacht and Lorentz Institute GNU/Linux workstations. In most cases, both python 2 (currently 2.7) and python 3 (currently 3.6) are available. | Python is available on all Sterrewacht and Lorentz Institute GNU/Linux workstations. In most cases, both python 2 (currently 2.7) and python 3 (currently 3.7) are available. |
| |
Notes from a [[https://www.strw.leidenuniv.nl/python/| python introduction course]] are available on the observatory web site. | Notes from a [[https://www.strw.leidenuniv.nl/python/| python introduction course]] are available on the observatory web site. |
* When globally installed packages are on the python path, and they satisfy the installation requirements, pip does nothing, and reports that requirement is satisfied. | * When globally installed packages are on the python path, and they satisfy the installation requirements, pip does nothing, and reports that requirement is satisfied. |
* pip will not perform a --user install in a virtualenv unless the virtualenv was created specifying ''--system-site-packages''. Nonetheless, pip will never install a package that conflicts with a package in the virtualenv site-packages. | * pip will not perform a --user install in a virtualenv unless the virtualenv was created specifying ''--system-site-packages''. Nonetheless, pip will never install a package that conflicts with a package in the virtualenv site-packages. |
| |
| === Method 1 - subsection Incompatible versions === |
| |
| Unfortunately, python's 'user' directory is independent of the operating system version, but most of the compute nodes including the LOFAR cluster, run RedHat Enterprise Linux, which is sufficiently different to cause packages installed on the desktop not to work all the time. |
| |
| In cases like this, it might be necessary to create a separate python user directory structure for those machines: |
| |
| Add to your .bashrc something like this: |
| if [ ! -f /etc/fedora-release ]; then |
| export PYTHONUSERBASE=$HOME/.local-rhel7 |
| fi |
| For users of the ''tcsh'' shell, add this to your .cshrc in stead: |
| if (! -f /etc/fedora-release) then |
| setenv PYTHONUSERBASE $HOME/.local-rhel7 |
| endif |
| |
| And make sure to create that directory ~/.local-rhel7. Now the pip --user commands on RHEL7 machines will install into that newly created directory in stead of the default one used by the desktop systems. |
| |
==== METHOD 2: virtualenv ==== | ==== METHOD 2: virtualenv ==== |
====== Bypassing the existing python environment ====== | ====== Bypassing the existing python environment ====== |
Occasionally, something in the systemwide directories (e.g ''/software/local/lib64/python2.7/site-packages'') interferes with your python application. Perhaps you have a code that requires a specific, older, version of numpy or matplotlib. Just installing that version is not always sufficient. The trick is, to set the PYTHONPATH to point first to a directory where you place a private ''sitecustomize.py'' which then overrides the one we have placed in /usr/lib64/python2.7/site-packages (which is where we add the /software directories to the path for everyone). Here is how: | Occasionally, something in the systemwide directories (e.g ''/software/local/lib64/python2.7/site-packages'') interferes with your python application. Perhaps you have a code that requires a specific, older, version of numpy or matplotlib. Just installing that version is not always sufficient. The trick is, to set the PYTHONPATH to point first to a directory where you place a private ''sitecustomize.py'' which then overrides the one we have placed in /usr/lib64/python2.7/site-packages (which is where we add the /software directories to the path for everyone). Here is how: |
<code sh> | <code bash> |
mkdir /some/location/python_custom_dir | mkdir /some/location/python_custom_dir |
setenv PYTHONPATH /some/location/python_custom_dir:/usr/lib64/python2.7/site-packages | setenv PYTHONPATH /some/location/python_custom_dir:/usr/lib64/python2.7/site-packages |