Error message for virtualenvwrapper on Mac OS X Yosemite 10.10.3
Asked Answered
A

5

16

I recently did a clean install of Mac OS 10.10.3 and am trying to set up a python environment. But I can't get virtualenvwrapper to work.

I installed python 2 and 3 using Homebrew.

$ which python
/usr/local/bin/python

$ which python3
/usr/local/bin/python3

$ which pip
/usr/local/bin/pip

$ which virtualenv
/usr/local/bin/virtualenv

$ which virtualenvwrapper.sh
/usr/local/bin/virtualenvwrapper.sh

Here are the lines in my .bash_profile

export PATH=/usr/local/bin:$PATH
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

The virtualenv works on its own with: $ source bin/activate

But when I source the virtualenvwrapper.sh. I get the following error message.

/usr/local/opt/python/bin/python2.7: 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/local/bin/python and that PATH is
set properly.

I can't figure out what went wrong. When I echo VIRTUALENVWRAPPER_PYTHON in the terminal. It returns the right path. In fact, all my paths are correct. They all point to the homebrew directory.

How can I get it to work?

Anteversion answered 19/4, 2015 at 16:2 Comment(4)
Did you install virtualenvwrapper for the appropriate python version?Costumier
I just did a pip install virtualenvwrapper.pip freeze returns virtualenvwrapper==4.5.0Anteversion
What's the first line of /usr/local/bin/pip say?Costumier
#!/usr/local/opt/python3/bin/python3.4. Is that the problem? Can I make python2 as default and explicitly specify python3 when I need it?Anteversion
M
24

It has been some time since this question was asked, but encountering the same issue, I'd like to add my solution in case someone might find it usefull:

Since virtualenvwrapper was installed using Python3, it is axpected that VIRTUALENVWRAPPER_PYTHON variable will point to Python3 path and not the Python2 path.

That is, in .bash_profile change:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python

To:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3

Then you can start using virtualwrapper, even if not installed for Python2 (unless you want to explicitly create the environment using Python2 in which case you'd probebly have to install it using pip2 and specify the relevant python path on the virtual environment creation command).

Matchmaker answered 17/4, 2017 at 20:8 Comment(0)
A
9

Per our comment exchange, you've installed virtualenvwrapper only on python 3. You need to also install it on python2. To do so:

curl -O https://bootstrap.pypa.io/get-pip.py python2.7 ./get-pip.py --user ~/.local/bin/pip install virtualenvwrapper My own setup is the opposite -- I use python2 for work, so install virtualenv for 3.x in ~/local -- hope that helps.

Thank you very much. Your answer points me to the right direction.

I solved the problem by uninstalling all things virtualenv.

pip uninstall virtualenv virtualenvwrapper

Then I installed everything again using pip2.7.

pip2.7 install virtualenv virtualenvwrapper

Now the terminal doesn't complain about can't find the module when I source virtualwrapper.sh

. /usr/local/bin/virtualenvwrapper.sh

However, python3 is the default python.

$ mkvirtualenv myenv
Using base prefix '/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4'
New python executable in myenv/bin/python3.4
Also creating executable in myenv/bin/python
Installing setuptools, pip...done.

To create a python2 env. I need to do this:

$ mkvirtualenv myenv --python /usr/local/bin/python
Running virtualenv with interpreter /usr/local/bin/python
New python executable in myenv/bin/python2.7
Also creating executable in myenv/bin/python
Installing setuptools, pip...done.
Anteversion answered 19/4, 2015 at 18:25 Comment(0)
C
1

Per our comment exchange, you've installed virtualenvwrapper only on python 3. You need to also install it on python2. To do so:

curl -O https://bootstrap.pypa.io/get-pip.py
python2.7 ./get-pip.py --user
~/.local/bin/pip install virtualenvwrapper

My own setup is the opposite -- I use python2 for work, so install virtualenv for 3.x in ~/local -- hope that helps.

Costumier answered 19/4, 2015 at 17:43 Comment(0)
P
0

This has fixed my issue

Assuming you have already added an alias for python2 (the default version of python in mac)

Add these on ~/.bash_profile

export WORKON_HOME=~/.virtualenvs
VIRTUALENVWRAPPER_PYTHON='/usr/local/bin/python3'
source /usr/local/bin/virtualenvwrapper.sh
Purchasable answered 30/7, 2018 at 6:39 Comment(0)
G
-1

just modify the VIRTUALENVWRAPPER_PYTHON environment variable into this:

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3

and then run it by typing

source ~/.bash_profile

Glottic answered 13/9, 2018 at 17:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.