Fix the Mkvirtualenv Command Not Found Error in Bash

  1. Fix the mkvirtualenv: command not found Error in Bash
  2. Install Virtual Environment on Linux-Based Systems

This article demonstrates how to fix the mkvirtualenv: command not found error in Bash.

Fix the mkvirtualenv: command not found Error in Bash

If you are trying to make a virtual environment in Python and see something like this,

[username]$ mkvirtualenv testEnv
-bash: mkvirtualenv: command not found

The shell cannot find anything installed under mkvirtualenv. A simple solution to this is adding the location of the necessary script to your terminal shell’s configuration file.

The exact steps differ slightly depending on what shell you are using. Of course, this is assuming that you have already installed Virtual Environment.

If you have not installed Virtual Environment, then scroll down in this article, where we explain how to install everything. If you have already installed Virtual Environment, then continue reading.

When using Bash, you must change your .bash_profile or .bashrc file. If you are using a login shell, then the commands need to be added to the .bash_profile file, and in any other case, you need to add this code to the .bashrc file.

If you do not know the difference or are unsure, add the command to your .bashrc file.

For the sake, open ~/.bash_profile or ~/.bashrc in any text editor and add the following lines to it:

source `which virtualenvwrapper.sh`

You could manually enter the location of your virtualenvwrapper.sh file as well. To find this location, you can enter the following in your terminal and get the location of your virtualenvwrapper.sh file.

which virtualenvwrapper.sh

You can then copy and paste this location into your shell configuration file. If you use the zsh shell, the command must be added to your ~/.zshrc file instead.

Once you have made these changes, open a new terminal (highly recommended).

These changes should work in almost every case. If not, there’s still one more thing we can try.

The path to your virtualenvwrapper.sh file can be outside the PATH folders in some obscure installations. However, we can still try to find it.

Entering the following command will return the location of the file regardless of where it is in the system:

find / -name virtualenvwrapper.sh

You can then copy this location and add it to your shell configuration file.

For example, suppose the location is: /usr/local/bin/virtualenvwrapper.sh (which we are only taking as an example, this wouldn’t happen because this should already be in your PATH). In that case, you can write the following line into your shell configuration file:

source /usr/local/bin/virtualenvwrapper.sh

And then open a new terminal again.

If nothing has worked, then there’s a chance that you have not installed Virtual Environment. In this case, we have a brief guide below to help you install Virtual Environment on Linux systems.

Install Virtual Environment on Linux-Based Systems

  1. Install pip.

If you are using Ubuntu, the command below should get you started:

sudo apt-get install python-pip

For information on installing on other Linux systems, click here

  1. Install Virtual Environment.
sudo pip install virtualenv

If you are using Python3, you may have to use the command below instead.

sudo pip3 install virtualenv
  1. Install the wrapper.
sudo pip install virtualenvwrapper

or

sudo pip3 install virtualenvwrapper

Afterward, go into your terminal configuration file, either ~/.bashrc or ~/.bash_profile. If you do not know which to use, ~/.bashrc will probably be appropriate.

Open the file in a text editor, and add the following command to it:

source /usr/local/bin/virtualenvwrapper.sh

Open a new terminal, and everything should be working!

Write for us
DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Bash Error

  • Syntax Error Near Unexpected Token in Bash
  • Solve GCC Command Not Found Error in Bash
  • Solve Unary Operator Expected Error in Bash