How To Setup Python Virtualenv on Ubuntu 17.10

Virtualenv python Ubuntu Pip Virtual Environments


Virtualenv is a powerful tool to create virtual python environments. Virtual python environments don't share installed packages with other environments. This is great if your applications require different versions of libraries. 

Installing necessary packages

Before we can install Virtualenv, let's run the commands below to install and update necessary packages.

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install build-essential

Install Virtualenv using apt-get

We can either install virtualenv using apt-get or pip. To install Virtualenv using Ubuntu apt-get package manager, run the command below:

sudo apt-get install python-virtualenv

Install Virtualenv using pip

Alternatively, to install virtualenv using pip, run the commands below.

sudo apt-get install python-pip

pip install virtualenv

Setting up and using virtualenv

To setup, a virtual python environment, run the commands below and replace "/pytest" with the directory where you want to create the virtualenv.

mkdir /pytest

cd /pytest

virtualenv .

Now we have the virtual environment setup, we can activate the virtualenv by using the following command.

source /pytest/bin/activate

Once you are done using the virtualenv, you can exit out of it by running:

    No comments found for this tutorial, be the first to leave a comment!

Tutorial by

Last updated on
Dec 28, 2017