Installing virtualenv Python

Introduction

In this article you will learn how to install Python virtualenv on Windows and Linux

Installation on Windows

In this article we will discuss specifically the installation of a virtual environment using virtualenv.

We will look at working in virtualenv in the next article

The venv package we will look at some day in the future.

python -m pip install virtualenv

Collecting virtualenv Downloading virtualenv-20.0.21-py2.py3-none-any.whl (4.7 MB) |████████████████████████████████| 4.7 MB 2.2 MB/s Requirement already satisfied: six<2,>=1.9.0 in c:\users\andrei\appdata\roaming\python\python38\site-packages (from virtualenv) (1.14.0) Collecting filelock<4,>=3.0.0 Downloading filelock-3.0.12-py3-none-any.whl (7.6 kB) Collecting distlib<1,>=0.3.0 Downloading distlib-0.3.0.zip (571 kB) |████████████████████████████████| 571 kB 2.2 MB/s Collecting appdirs<2,>=1.4.3 Downloading appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB) Could not build wheels for six, since package 'wheel' is not installed. Could not build wheels for distlib, since package 'wheel' is not installed. Installing collected packages: filelock, distlib, appdirs, virtualenv Running setup.py install for distlib ... done Successfully installed appdirs-1.4.4 distlib-0.3.0 filelock-3.0.12 virtualenv-20.0.21

Run

virtualenv --version

virtualenv 20.0.21 from c:\users\andrei\appdata\local\programs\python\python38-32\lib\site-packages\virtualenv\__init__.py

Installation on Linux

As an example, here is the installation of virtualenv on Ubuntu

python3 -m pip install virtualenv

Ideally you will get similar messages

Collecting virtualenv Using cached virtualenv-20.0.35-py2.py3-none-any.whl (4.9 MB) Requirement already satisfied: six<2,>=1.9.0 in /usr/lib/python3/dist-packages (from virtualenv) (1.14.0) Requirement already satisfied: distlib<1,>=0.3.1 in /home/andrei/.local/lib/python3.8/site-packages (from virtualenv) (0.3.1) Requirement already satisfied: appdirs<2,>=1.4.3 in /home/andrei/.local/lib/python3.8/site-packages (from virtualenv) (1.4.4) Requirement already satisfied: filelockU<4,>=3.0.0 in /home/andrei/.local/lib/python3.8/site-packages (from virtualenv) (3.0.12) Installing collected packages: virtualenv Successfully installed virtualenv-20.0.35

Now you can run

virtualenv --version

And find out your virtualenv version

virtualenv 20.0.35 from /home/andrei/.local/lib/python3.8/site-packages/virtualenv/__init__.py

Possible problems

During installation Linux may warn you about problems. Consider the example log after running python3 -m pip install virtualenv

Collecting virtualenv Downloading virtualenv-20.0.35-py2.py3-none-any.whl (4.9 MB) |████████████████████████████████| 4.9 MB 6.2 MB/s Collecting filelock<4,>=3.0.0 Downloading filelock-3.0.12-py3-none-any.whl (7.6 kB) Collecting distlib<1,>=0.3.1 Downloading distlib-0.3.1-py2.py3-none-any.whl (335 kB) |████████████████████████████████| 335 kB 4.9 MB/s Requirement already satisfied: six<2,>=1.9.0 in /usr/lib/python3/dist-packages (from virtualenv) (1.14.0) Collecting appdirs<2,>=1.4.3 Downloading appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB) Installing collected packages: filelock, distlib, appdirs, virtualenv WARNING: The script virtualenv is installed in '/home/andrei/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed appdirs-1.4.4 distlib-0.3.1 filelock-3.0.12 virtualenv-20.0.35

Pay attention to the WARNING. The system warned that the directory in which virtualenv is installed is not listed in PATH.

Read more about PATH in Linux in a separate article from which you can learn that to add to $PATH you need to run

export PATH="/home/andrei/.local/bin:$PATH"

Uninstalling virtualenv on Linux

To uninstall virtualenv on Ubuntu use the command

python3 -m pip uninstall virtualenv

Found existing installation: virtualenv 20.0.35 Uninstalling virtualenv-20.0.35: Would remove: /home/andrei/.local/bin/virtualenv /home/andrei/.local/lib/python3.8/site-packages/virtualenv-20.0.35.dist-info/* /home/andrei/.local/lib/python3.8/site-packages/virtualenv/* Proceed (y/n)? y Successfully uninstalled virtualenv-20.0.35

Article author: Andrei Olegovich