This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
working_with_python [2023/11/03 15:42] – [Jupyter Notebooks] jansen | working_with_python [2025/04/07 15:07] (current) – Modified example for RHEL9 jansen | ||
---|---|---|---|
Line 73: | Line 73: | ||
=== Method 1 - subsection Incompatible versions === | === Method 1 - subsection Incompatible versions === | ||
- | Unfortunately, | + | Unfortunately, |
In cases like this, it might be necessary to create a separate python user directory structure for those machines: | In cases like this, it might be necessary to create a separate python user directory structure for those machines: | ||
Line 79: | Line 79: | ||
Add to your .bashrc something like this: | Add to your .bashrc something like this: | ||
if [ ! -f / | if [ ! -f / | ||
- | export PYTHONUSERBASE=$HOME/ | + | export PYTHONUSERBASE=$HOME/ |
fi | fi | ||
For users of the '' | For users of the '' | ||
if (! -f / | if (! -f / | ||
- | setenv PYTHONUSERBASE $HOME/ | + | setenv PYTHONUSERBASE $HOME/ |
endif | 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. | + | And make sure to create that directory ~/.local-rhel9. Now the pip --user commands on RHEL9 machines will install into that newly created directory in stead of the default one used by the desktop systems. |
- | ==== METHOD 2: virtualenv ==== | + | ==== METHOD 2: venv ==== |
+ | |||
+ | '' | ||
+ | <code bash> | ||
+ | $ mkdir / | ||
+ | $ python3 -m venv / | ||
+ | </ | ||
+ | to create a virtual environment (folder) called pymatlab (note that this example explicitly creates this in a directory on your local ''/ | ||
+ | |||
+ | In the example, we use '' | ||
+ | |||
+ | The last step before starting to use the newly generated environment is to activate it, that is to prepend its ''/ | ||
+ | <code bash> | ||
+ | source / | ||
+ | source / | ||
+ | </ | ||
+ | |||
+ | To acknowledge the activation of pymatlab, the terminal prompt will be changed to | ||
+ | <code bash> | ||
+ | (pymatlab)username@hostname: | ||
+ | </ | ||
+ | to emphasize that you are operating in a virtual environment. To install pymatlab (or any other package) locally (in your virtual environment) run pip within that environment | ||
+ | <code bash> | ||
+ | pip install | ||
+ | </ | ||
+ | Your virtual environment now should have the same core python packages defined globally for all the Observatory or Lorentz Institute | ||
+ | Note that you do NOT use '' | ||
+ | |||
+ | In any cases, it is advisable you keep a backup of your virtual environment configuration by creating a list of installed packages | ||
+ | <code bash> | ||
+ | pip freeze > packages.dat | ||
+ | </ | ||
+ | This can help collaborators and fellow developers to reproduce your environment with | ||
+ | <code bash> | ||
+ | pip install -r packages.dat | ||
+ | </ | ||
+ | When you are done working in a virtual environment deactivate it running | ||
+ | <code bash> | ||
+ | deactivate | ||
+ | </ | ||
+ | At any time, any virtual environment can be destroyed by removing the corresponding folder from the file system so do not panic if things do not work, just delete your virtual environment and start all over again. | ||
+ | |||
+ | Note: __System administrators will not be responsible and/or manage users virtual environments__. You are strongly advised you consult the documentation. | ||
+ | |||
+ | ==== METHOD 2: OBSOLETE: virtualenv (python 2.x) ==== | ||
This guide refers to virtualenv version 12.0.7. | This guide refers to virtualenv version 12.0.7. | ||
Line 273: | Line 317: | ||
After starting '' | After starting '' | ||
+ | |||
+ | If you need to work with several python setups (e.g. the system python3, but also from loaded environment modules), it is easy to assign a name to the generated kernel, e.g: | ||
+ | python3 -m ipykernel install --user --name system-python3 | ||
+ | |||
+ |