'How to check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python etc

I'm following this guide on virtualenv for Python and have run into a little problem:

Sahands-MBP:empty sahandzarrinkoub$ source /usr/local/bin/virtualenvwrapper.sh
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.

The printout is quite helpful. It says that I need to check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly. The only problem is, I don't know what these things mean. So my questions are:

  1. What does it mean that virtualenvwrapper has been "installed for" VIRTUALENVWRAPPER_PYTHON=/usr/bin/python.
  2. What is a properly set PATH in this case?


Solution 1:[1]

Not exactly sure what you are needing, but maybe this will help. It is a little verbose, but hopefully will answer your questions:

There are a number of things going on here.

First, /usr/local/bin/virtualenvwrapper.sh is a shell script. If you read the script, you will see the following code:

# Locate the global Python where virtualenvwrapper is installed.
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] 
then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
fi

What this means is that the virtualenvwrapper.sh script uses an environmental variable named VIRTUALENVWRAPPER_PYTHON to determine the python installation. This is important because:

Second, multiple versions of python can be installed on a system. (I currently have 3: 2.7, 3.5, and 3.6). And with Linux systems anyway,

/usr/bin/python

is symbolically linked to one of those versions. This is how it looks on my system Linux system:

lenovo:davidj ~ >  ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 Apr 28 23:36 /usr/bin/python -> 
/etc/alternatives/python
 lenovo:davidj ~ >  ls -l /etc/alternatives/python
lrwxrwxrwx 1 root root 18 Aug 31 14:56 /etc/alternatives/python -> 
/usr/bin/python3.6

So, following the chain of symbolic links, when I run

/usr/bin/python

I am running version 3.6. I can change those links at will to point to version 2.7, 3.5, or any other version I might install.

What all of this means is this: unless you have VIRTUALENVWRAPPER_PYTHON set to a specific python installation, /usr/local/bin/virtualenvwrapper.sh will default to /usr/bin/python to determine the default python version you are running.

In my case, in my .bashrc file I have

export VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3.6'

This means that virtualenvwrapper will use python 3.6 because I am telling it to use that specific version.

In your case, the script is failing because virtualenvwrapper is not installed for that version of python that /usr/bin/python points to. To determine your version of python simply run:

python -V

and then install virtualenvwrapper for that version.

I hope this helps.

Solution 2:[2]

You just need added this row to ~/.zshrc or .bash_profile:

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2

Solution 3:[3]

Since my Debian 11 does not have python 2.7, I just did:

sudo ln -s /usr/bin/python3 /usr/bin/python

No colateral efects have been observed

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Jenkins
Solution 2 Eds_k
Solution 3 André Duarte