We may face issues when our Linux distribution only offers certain versions of Python and its packages, when we actually need newer or older versions.
We can install new versions of Python on the server, however this will be more complex because we will have some dependency issues when trying to compile everything we need.
Virtual environments make this very easy to manage and set up, we can have different versions of Python and packages in each environment, and it will be isolated from the main system.
Installing Virtual Environment on Ubuntu 18.04 -or later from 16.04, is fairly easy task and it shouldn’t take more then 10 minutes to finish.
install pip3 if you don’t have already
$ sudo apt-get install python3-pip
$ sudo pip3 install virtualenv
build new virtualenv
$ cd $YOUR_PROJECT_DIRECTORY $ virtualenv .venv
.venv or any
$NAME for your virtualenv
to activate your virtualev
$ source .venv/bin/activate
and you see your
to deactivate your virtualev
install new packages
After activating your virtualenv
$ pip install <some-package>
You can also use
Python2.7 interpreter for your
virtualenv but I would not recommend that since Python 2.7 will not be maintained after January 1, 2020. But if you like to:
$ virtualenv -p /usr/bin/python2.7 .venv
If you are enjoying my content, maybe you would enjoy buying me a coffee as well.
Just a food for thought.