54

Lots of other threads about similar issues, but none that I could find where quite the same case as mine. So, here goes:

Things I did:

  • Ran: sudo easy_install pip
  • Ran: sudo pip install virtualenv
  • Ran: sudo pip install virtualenvwrapper

Current State:

  • .bash_profile

    export PATH=/usr/local/bin:$PATH
    export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
    export WORKON_HOME=$HOME/.virtualenvs
    export PIP_VIRTUALENV_BASE=$WORKON_HOME
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
    
  • Running mkvirtualenv test results in:

    New python executable in trunk/bin/python
    Installing setuptools, pip...done.
    /usr/bin/python: No module named virtualenvwrapper
    
  • Manually inspecting '/usr/local/bin' shows that virtualenvwrapper.sh exists

  • Unlike some other questions I saw about this, I get no message about virtualenvwrapper when I start a new terminal window
  • Running 'which python' results in: /usr/bin/python

What I've tried:

  • Inspecting my path to make sure it looks like it is supposed to
  • Reinstalling pip, then using the reinstalled pip to reinstall virtualenv and virtualenvwrapper

Any help getting this working would be very much appreciated.

user3699754
  • 549
  • 1
  • 4
  • 3
  • 1
    What is your default version of Python? Pip will install to whatever Python version is the current default (2.7, 3.3). If you install a package for say Python 2.7 you cannot use it in Python 3.3 . Double check that the `/usr/bin/python` directory is where your default version of Python is located. – Elias Jun 02 '14 at 14:55
  • I was under the impression that 'which python' did that and it returned /usr/bin/python. Is that not correct? – user3699754 Jun 02 '14 at 15:22

10 Answers10

89

I've managed to get this working after having the same problem you've described here by editing my ~/.bash_profile and adding this:

export WORKON_HOME=$HOME/code/.virtualenvs
export PROJECT_HOME=$HOME/code
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'

source /usr/local/bin/virtualenvwrapper.sh

Save, close.

then:

$ source ~/.bash_profile

and:

$ mkvirtualenv test
user3418052
  • 991
  • 7
  • 4
  • 14
    On MacOS `/usr/local/bin/python` is the one installed by `brew`. `/usr/bin/python` is the one from the system. It's easier to use python from `brew` with `virtualenvwrapper` so `export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python` is the important part here. You can also install `python3` with `brew` and use `/usr/local/bin/python3` instead if you prefer . – GabLeRoux Aug 03 '17 at 14:14
  • @GabLeRoux thanks for that compressed Answer in comment. – KeitelDOG Mar 05 '19 at 14:23
41

I had the same problem setting up virtualenvwrapper on ubuntu.

I had installed virtualenv, virtualenvwrapper using pip which installed these modules in the site package of python3.5. How did I find that out?

Open your terminal and type

$ pip --version

pip 9.0.1 from /home/clyton/.virtualenvs/test1/lib/python3.5/site-packages (python 3.5)

Then I checked the variable VIRTUALENVWRAPPER_PYTHON whose value was /usr/bin/python. On your terminal and type

$ ls -l $VIRTUALENVWRAPPER_PYTHON

lrwxrwxrwx 1 root root 9 Dec 10  2015 **/usr/bin/python -> python2.7**

As you can see this variable is pointing to python2.7 and you may have installed virtualenv in a different python site package.

So to fix this problem, just add the below line in your bashrc

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.5

NOTE: Set the above value to the python version with which virtualenv was installed. In my case it was python3.5 so I have set that value. How to find out the python version used to install virtualenv? Again type pip --version in the terminal.

Then open a new shell session and try mkvirtualenv again. This time it should work.

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
Clyt
  • 616
  • 1
  • 7
  • 13
15

If you take a look at the virtualenvwrapper.sh script, you will find these lines:

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

If you don't manually export VIRTUALENVWRAPPER appropriately for your version of python, it will assume the system default where you don't have the virtualenvwrapper package installed.

I fixed this like so:

echo "export VIRTUALENVWRAPPER_PYTHON=$(which python3.6)" >> ~/.zshrc

This is all documented on the official website here.

wulfgarpro
  • 6,666
  • 12
  • 69
  • 110
7

try installing virtualenv and virtualenvwrapper with pip2 install virtualenv virtualenvwrapper. it seems like pip install virtualenv and it's wrapper to python 3 as it's default

asem bused
  • 115
  • 3
  • 8
3

In my case, adding this line into my .zshrc file did the trick,

export VIRTUALENVWRAPPER_PYTHON=/usr/local/Cellar/python/2.7.13/bin/python2.7

remember to source ~/.zshrc to update the change to your current terminal.

pecai
  • 121
  • 1
  • 1
  • Same issue, don't get why, just tired wasting my time. Using `/usr/local/Cellar/python/2.7.14_2/bin/python2.7` did the trick, thanks – Vadorequest Jan 22 '18 at 15:12
  • In my case the issue was that it was using python2 which didn't have virtualenvwrapper installed. Editing virtualenvwrapper.sh and changing the path like so worked: `VIRTUALENVWRAPPER_PYTHON="$(command \which python3)"` – Ran Halprin Sep 10 '20 at 21:29
3

Got this error after recently (summer 2017) updating Homebrew and python. The issue in my case was that Homebrew no longer overwrites the system python and I didn't have virtualenv and virtualenvwrapper installed for the system python.

The solution in my case was to add the following to ~/.bash_profile (or ~/.zshrc):

export PATH="$(brew --prefix)/opt/python/libexec/bin:$PATH"

This made python point to the brew version of python and also gave me pip back. This version of python had virtualenv and virtualenvwrapper installed so the error no longer appeared. See the caveats section under brew info python and https://github.com/Homebrew/homebrew-core/issues/15746 for more information

bjorgvin
  • 186
  • 2
  • 5
2

Try to uninstall your virtualenv and virtualenvwrapper and install it again using pip (check if you symlink your pip or assigned an alias on it for other version) in version 2.7 (I think).

I encountered the same error and I just did this and solved my problem.

I using Ubuntu machine.

I hope this help.

manilaT
  • 55
  • 7
0

I don't know if it's relevant to anyone but I got this error while editing ~/.zshrc while virtualenv being active. So I had to deactivate and then rmvirtualenv env_name to remove the errors. And then I recreated the env: mkvirtaulenv env_name and workon env_name and this time I got no errors.

Hope it helps someone.

abe312
  • 2,547
  • 25
  • 16
0

I realize this thread is super old but I got stuck on it while trying to find a solution to this problem (using pip3 but you can swap pip as necessary).
I ended up using a modified version of a solution that I found in another post here.
Add the following to your .zshrc/.bashrc:

source /usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3

I had to add local in the above but guessing that whether or not you need to do so will depend on your installation. I realized I was referencing the wrong location because I was getting this error: zsh: no such file or directory: /usr/bin/python3 so I just did which python3 to see where it lived.

Make sure you uninstall any existing versions of virtualenv and virtualenvwrapper as you can not simply install to a new location with an existing version on your machine, you must delete the old version and then install the new version in the new location.

To install:
sudo /usr/local/bin/pip3 install virtualenv virtualenvwrapper

And, as per this post, you should be able to create a virtual environment with your version of python3 using this command:

mkvirtualenv --python=`which python3` nameOfEnvironment
Onema
  • 7,331
  • 12
  • 66
  • 102
Keith
  • 154
  • 1
  • 8
0

In Ubuntu 20.xx, virtual env can be created only by specifying python executable path.

$ which python3
/usr/bin/python3
$ mkvirtualenv --python=/usr/bin/python <name_of_your_virtual_env>
Harsha N Hegde
  • 315
  • 2
  • 14