How to install virtualenv on Ubuntu (and CentOS-8)
R.Schramm Notes
- Captured this document from the web and converted to markdown.
- Tested to work on Ubuntu 18.04 and 20.04 navprocs for both python3 and python 2.7 on 05-Mar-2021
- I appended a section at the bottom of some notes for installing on CentOS-8
Begin Captured Article
Author: Serhat Teker Posted Apr 27, 2020
Link to Original Article
Sep 11, 2019 Originally published at tech.serhatteker.com on Dec 15, 2018
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 pip
install pip3 if you don't have already
$ sudo apt-get install python3-pip
Install virtualenv
$ sudo pip3 install virtualenv
Build new virtualenv
Note
use any name you like for your virtualenv
$ cd $YOUR_PROJECT_DIRECTORY $ virtualenv my_venv
To activate your virtualev
$ source my_venv/bin/activate
and you see your venv activated
(my_venv) ~/project$
to deactivate your virtualev
$ deactivate
Install new packages
After activating your virtualenv
$ pip install <some-package>
Note
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 my_venv
R.Schramm - Notes on installing virtualenv for CentOS-8
Installation on Centos uses 'yum' commands instead of 'pip'.
We assume python3 is installed by on your local machine.
Python 3.6.8 is installed by default on Centos8
The commands below were successful on MBARI machine coredata8 (CentOS-*) circa early 2021
sudo yum install virtualenv
cd $YOUR_PROJECT_DIRECTORY
python3 -m venv my_env
source env/bin/activate