Commit 74854f4d authored by Michael Krause's avatar Michael Krause 🎉
Browse files

software: update virtual env things

parent 83b18a20
......@@ -9,8 +9,8 @@ Versions
Users need to be aware, that there are still two major versions around that are not 100% compatible to each other.
Although Python 3.0 was released back in 2008, its predecessor Python 2.7 is still around and not all libraries and packages have migrated.
Since the system version on Debian/stable is still 2.7, the :file:`python` program always points to Python 2 (2.7.3).
The :file:`python3` program designates the counterpart (3.2).
Since the system version on Debian/stable is still 2.7, the :file:`python` program always points to Python 2 (2.7).
The :file:`python3` program designates the counterpart (3.5).
The system and core python libraries are, though stable, still quite old (even in the Python 3 branch).
You can use environment modules to switch to a newer version.
......@@ -21,20 +21,14 @@ Example:
# system libraries
[krause@master ~] python --version
Python 2.7.3
Python 2.7.13
[krause@master ~] python3 --version
Python 3.2.3
Python 3.5.3
# load new version for python 3
[krause@master ~] module load python/3.5
[krause@master ~] module load python/3.6
[krause@master ~] python3 --version
Python 3.5.1
# load new version for python 2
[krause@master ~] module unload python
[krause@master ~] module load python/2.7
[krause@master ~] python --version
Python 2.7.12
Python 3.6.3
......@@ -62,9 +56,10 @@ Of course it comes separately for Python 2 and 3:
.. code-block:: bash
[krause@master ~] pip --version
pip 1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
[krause@master ~] pip3 --version
pip 9.0.1 from /home/mpib/krause/.local/lib/python3.5/site-packages (python 3.5)
pip 9.0.1 from /opt/software/python/3.6.3/lib/python3.6/site-packages (python 3.6)
To install a package in your home directory, you can simply run :program:`pip3 install --user <packagename>`.
......@@ -107,28 +102,33 @@ convenient to use different python environments for each project.
Starting with Python 3.4 the program `pyvenv`_ will help you manage different environments.
Once created it will copy the current system version's python and pip to a new directory with the environment's name.
Every package installed or upgraded will be contained to that specific directory and you can switch between them very easily.
For convenience reasons we also installed a module called `virtualenvwrapper`_, which provides three important commands to handle environments: `mkvirtualenv`, `workon`, and `deactivate`.
**Create a new virtual environment**
.. code-block:: bash
[krause@master ~] module load python/3.5 # global tardis environment
[krause@master ~] pyvenv .venvs/project # python environment
[krause@master ~] mkvirtualenv --python=/usr/bin/python3 project
(project) [krause@master ~]
**Activate and use the virtual environment**
.. code-block:: bash
[krause@master ~] source .venvs/project/bin/activate
# without virtual environment
[krause@master ~] python --version
Python 2.7.13
# with virtual environment
[krause@master ~] workon project
(project) [krause@master ~] python --version
Python 3.5.3
(project) [krause@master ~] which python3
/home/mpib/krause/.venvs/project/bin/python3
(project) [krause@master ~] which pip3
/home/mpib/krause/.venvs/project/bin/pip3
(project) [krause@master ~] pip3 --version
ppip 7.1.2 from /home/mpib/krause/.venvs/project/lib/python3.5/site-packages (python 3.5)
(project) [krause@master ~] python3 --version
Python 3.5.1
/home/mpib/krause/.virtualenvs/project/bin/python
[krause@master ~] pip --version
pip 9.0.1 from /home/mpib/krause/.virtualenvs/project/lib/python3.5/site-packages (python 3.5)
**Deactivate the virtual environment**
......@@ -139,7 +139,8 @@ Every package installed or upgraded will be contained to that specific directory
[krause@master ~]
Note how :file:`pyvenv` is also managing your shell prompt, so you always know which Python environment you are currently running.
Note how :file:`virtualenv` is also managing your shell prompt, so you always know which Python environment you are currently running.
.. _PyPI: https://pypi.python.org/pypi
.. _pyvenv: https://packaging.python.org/installing/#creating-virtual-environments
.. _pyvenv: https://virtualenvwrapper.readthedocs.io/en/latest
.. _virtualenvwrapper: https://packaging.python.org/installing/#creating-virtual-environments
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment