Fix mkvirtualenv command not found on Ubuntu

You can download this article in PDF format via the link below to support us.Download the guide in PDF formatClose

In this short tutorial, we will show you how to install mkvirtualenv (virtualenvwrapper and virtualenv) on an Ubuntu Linux machine. virtualenvwrapper is a set of Shell functions defined using Bourne Shell compatible syntax. virtualenv enables you to create many different Python environments in Linux/macOS systems. With virtualenvwrapper, you can automate tests run under the following Shell on Linux or OS X computers.

  • bash
  • ksh
  • zsh

If I try to type mkvirtualenv in the terminal, this is the error I get.

$ mkvirtualenv
mkvirtualenv: command not found

You need to install the virtualenvwrapper package into the same global site package area where virtualenv is installed. This installation requires administrative privileges. Make sure you are logged in as a root user or a standard user with sudo privileges.

Update the system package list.

sudo apt update

Then install the Python build tools.

# Python 2
sudo apt-get install python-pip python-dev build-essential

# Python 3
sudo apt-get install python3-pip python3-dev build-essential

Then install the virtualenv and virtualenvwrapper packages.

Use APT package manager:

sudo apt install virtualenv virtualenvwrapper

Bring ideas:

# Python 2
$ sudo pip install virtualenv virtualenvwrapper

# Python 3
$ sudo pip3 install virtualenv virtualenvwrapper

Another way to install it into the global site package is to add it to Your user local directory (Usually ~/.local). See the following example:

$ pip install --user virtualenv virtualenvwrapper

Configure your Shell

Depending on your installation method, you may need to add the virtualenvwrapper script path to the startup file (.bashrc, .profile, etc.).

But first confirm the location of the virtualenvwrapper script.

$ sudo find / -name virtualenvwrapper.sh
/usr/share/virtualenvwrapper/virtualenvwrapper.sh

Then edit ~/.bashrc And add a line in the source /usr/share/virtualenvwrapper/virtualenvwrapper.sh

$ vim ~/.bashrc
source '/usr/share/virtualenvwrapper/virtualenvwrapper.sh'

Now get your bashrc file.

$ source ~/.bashrc
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/get_env_details

You can also set WORKON_HOME Variables for custom paths, by default $HOME/.virtualenvs.

export WORKON_HOME=/my/other/path

If the directory does not exist when virtualenvwrapper is loaded, it will be created automatically.

Try to run the mkvirtualenv command:

$ mkvirtualenv -p /usr/bin/python3 test_venv
created virtual environment CPython3.8.2.final.0-64 in 448ms
  creator CPython3Posix(dest=/home/computingforgeeks/.virtualenvs/test_venv, clear=False, global=False)
  seeder FromAppData(download=False, pep517=latest, requests=latest, appdirs=latest, progress=latest, lockfile=latest, certifi=latest, urllib3=latest, packaging=latest, pyparsing=latest, chardet=latest, six=latest, pip=latest, colorama=latest, CacheControl=latest, pkg_resources=latest, webencodings=latest, ipaddr=latest, distlib=latest, contextlib2=latest, html5lib=latest, pytoml=latest, setuptools=latest, msgpack=latest, wheel=latest, idna=latest, distro=latest, retrying=latest, via=copy, app_data_dir=/home/computingforgeeks/.local/share/virtualenv/seed-app-data/v1.0.1.debian)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/test_venv/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/test_venv/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/test_venv/bin/preactivate
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/test_venv/bin/postactivate
virtualenvwrapper.user_scripts creating /home/computingforgeeks/.virtualenvs/test_venv/bin/get_env_details

To run your project virtual environment at any time:

$ workon test_venv

Exit operation:

$ deactivate

You should now be able to use virtualenv and virtualenvwrapper scripts to work on Python projects.

Other articles related to Python:

How to install Python 2 using Virtualenv on Ubuntu

Use Apache and mod_wsgi to deploy Python 3 Django applications on CentOS 7

The best books to learn Python programming

Python learning video:


Complete Python Bootcamp in 2020: From Zero to Hero in Python

★★★★★ (318545) $12.96 $153.19 in stock

Buy now

Fix mkvirtualenv command not found on UbuntuUdemy.com


Use Python programming to automate boring tasks

Use Python programming to automate boring tasks

★★★★★ (70561) $12.96 $58.91 in stock

Buy now

Fix mkvirtualenv command not found on UbuntuUdemy.com


Python for data science and machine learning bootcamp

Python for data science and machine learning bootcamp

★★★★★ (87481) $ 12.96 $ 153.19 in stock

Buy now

Fix mkvirtualenv command not found on UbuntuUdemy.com You can support us by downloading the article in PDF format from the link below.Download the guide in PDF formatClose

Sidebar