Python in virtual environments
Python 3 is already integrated in our Linux Ubuntu 20 distribution. We can easily check this by querying the version of Python:
__$ python3 –V
When I copy and paste the above command, I get the message can't open file '-V'
:
python3: can't open file '–V': [Errno 2] No such file or directory
As the error suggests, the python3
command treats the following parameter -V
or --version
as a filename.
If, on the other hand, the command is typed in manually, the version appears:
Python 3.8.10
Python applications that depend on pip packages should ideally run in their own virtual environments. The background is that pip packages are usually installed globally. This can lead to problems when packages are updated and applications become incompatible with them.
venv module
With the venv
module, Python applications can be encapsulated. We simply install the software extension with apt
:
__$ sudo apt install -y python3-venv
We will come back to the module later when we create the application.