How to Install virtualenv tool for Creating Python Virtual Environment in Ubuntu Linux 18.04

Posted on

This is an article specifically for installing ‘virtualenv’ package or tool. In the manual page, virtualenv is a package for creating a python virtual environment. One of the advantage provided in python programming language is the existance of python virtual environment. It is an isolated environment where the module management is limited only in that environment. The following are steps for installing virtualenv tool or package in Ubuntu Linux 18.04 :

1. Chcek the availability of the ‘virtualenv’ tool or package in Ubuntu Linux 18.40. Just execute the following command in the command line :

user@hostname:~/python$ apt list --installed | grep virtualenv

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

python3-virtualenv/bionic,now 15.1.0+ds-1.1 all [installed,automatic]
virtualenv/bionic,now 15.1.0+ds-1.1l all [installed]
user@hostname:~/python$

There is a specific difference between the two of the above packages. Although both of them have the same function for creating python virtual environment, they are for different python version. The first one, python3-virtualenv is for python 3 and the next one is for the old version of python. Check the information of the package using the command ‘apt show package_name’. The following is the output showing information bout python3-virtualenv :

user@hostname:~/python$ apt show python3-virtualenv
Package: python3-virtualenv
Version: 15.1.0+ds-1.1
Priority: optional
Section: universe/python
Source: python-virtualenv
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 140 kB
Depends: python-pip-whl (>= 8.1.1-2), python3, python3-distutils, python3-pkg-resources, python3:any (>= 3.3.2-2~)
Homepage: https://pypi.python.org/pypi/virtualenv
Download-Size: 43.4 kB
APT-Manual-Installed: no
APT-Sources: http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
Description: Python virtual environment creator
 The virtualenv utility creates virtual Python instances, each invokable
 with its own Python executable.  Each instance can have different sets
 of modules, installable via easy_install.  Virtual Python instances can
 also be created without root access.
 .
 This is the Python 3 version of the library.

user@hostname:~/pytho

On the other hand, virtualenv also has the same function but it is for the old version or the original version of python as in the information follows :

E: Command line option 's' [from -s] is not understood in combination with the other options.
user@hostname:~/python$ apt show virtualenv
Package: virtualenv
Version: 15.1.0+ds-1.1
Priority: optional
Section: universe/python
Source: python-virtualenv
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 30.7 kB
Depends: python3, python3-virtualenv
Breaks: python-virtualenv (<< 1.11.6)
Replaces: python-virtualenv (<< 1.11.6)
Homepage: https://pypi.python.org/pypi/virtualenv
Download-Size: 4,476 B
APT-Manual-Installed: yes
APT-Sources: http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
Description: Python virtual environment creator
 The virtualenv utility creates virtual Python instances, each invokable
 with its own Python executable.  Each instance can have different sets
 of modules, installable via easy_install.  Virtual Python instances can
 also be created without root access.
 .
 This is the command line script and manpage.

user@hostname:~/python$ 

If the above output for checking the installed virtualenv is not exist, just execute the following command to install the virtualenv. Depends on the installed python available in the system, adjust the virtualenv package name. Do it either as follows :

apt-get -y install python3-virtualenv

or do the other version :

apt-get -y install virtualenv

Last but not least, execute the following command to check if the ‘virtualenv’ tool or package is a success :

user@hostname:~/python$ virtualenv
You must provide a DEST_DIR
Usage: virtualenv [OPTIONS] DEST_DIR

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -v, --verbose         Increase verbosity.
  -q, --quiet           Decrease verbosity.
  -p PYTHON_EXE, --python=PYTHON_EXE
                        The Python interpreter to use, e.g.,
                        --python=python3.5 will use the python3.5 interpreter
                        to create the new environment.  The default is the
                        interpreter that virtualenv was installed with
                        (/usr/bin/python)
  --clear               Clear out the non-root install and start from scratch.
  --no-site-packages    DEPRECATED. Retained only for backward compatibility.
                        Not having access to global site-packages is now the
                        default behavior.
  --system-site-packages
                        Give the virtual environment access to the global
                        site-packages.
  --always-copy         Always copy files rather than symlinking.
  --relocatable         Make an EXISTING virtualenv environment relocatable.
                        This fixes up scripts and makes all .pth files
                        relative.
  --no-setuptools       Do not install setuptools in the new virtualenv.
  --no-pip              Do not install pip in the new virtualenv.
  --no-wheel            Do not install wheel in the new virtualenv.
  --extra-search-dir=DIR
                        Directory to look for setuptools/pip distributions in.
                        This option can be used multiple times.
  --download            Download pre-installed packages from PyPI.
  --no-download, --never-download
                        Do not download pre-installed packages from PyPI.
  --prompt=PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --setuptools          DEPRECATED. Retained only for backward compatibility.
                        This option has no effect.
  --distribute          DEPRECATED. Retained only for backward compatibility.
                        This option has no effect.
  --unzip-setuptools    DEPRECATED.  Retained only for backward compatibility.
                        This option has no effect.
user@hostname:~/python$ 

Since the command of working because of the generated output above, the installation of ‘virtualenv’ package is finished.

One thought on “How to Install virtualenv tool for Creating Python Virtual Environment in Ubuntu Linux 18.04

Leave a Reply