This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
working_with_python [2023/11/06 13:12] – [Jupyter Notebooks] jansen | working_with_python [2024/04/22 10:51] (current) – jansen | ||
---|---|---|---|
Line 88: | Line 88: | ||
And make sure to create that directory ~/ | And make sure to create that directory ~/ | ||
- | ==== 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. | ||