Professional Documents
Culture Documents
HOWTO - Using Python in A Virtual Environment On Linux-V1.0
HOWTO - Using Python in A Virtual Environment On Linux-V1.0
When you install several Python3 versions – you shouldn't be using Python2 anymore, but this
HOWTO is applicable to it as well – and perhaps multiple modules for each, then chaos is almost
guaranteed and at the end none of the installations may work anymore due to various conflicts!
Whenever you want to install more than a single Python3 version on your computer, you should put
them in a Python-specific Virtual Environment (VE). Such a VE is different from “virtual
machines” of whole computing environments, and fortunately a whole lot simpler!
For the purpose of testing of GeigerLog I am currently running Python in versions 3.5, 3.6, 3.7, 3.8,
3.9. Each version of Py is allowed to load exactly the modules needed by it, and in exactly the
required module version.
But even if I had only a single Py version, but two or more Python programs, which each required a
module in a specific version, different from what the others needed, I could solve this problem with
a Python Virtual environment.
Using GeigerLog as example, I’ll show what the steps are.
The folder with the GeigerLog code will not be changed, moved, or copied. It will remain a single
installation, and all virtual Pythons will access it. Of course, nothing prevents me from making
copies of GeigerLog and perhaps modify them specifically for each virtual installation, but it is not
required!
The I change into folder GL:
user@mymachine:~$ cd /home/user/GL
Your terminal then shows code at the beginning of each line – here highlighted in red – that you are
working in a virtual Python environment:
(vgl3X) user@mymachine:~/GL$
All further Python and Pip commands will now go ONLY into this VE.
The “-U” is short for “--upgrade”; if not given the existing Pip would be kept, even if a newer one
were available.
and all others entered as a single line with a space between all module names.
and you will get a terminal line without the “(vgl3X)” at the beginning:
user@mymachine:~/GL$
When you now use Python you will be using your default installation.