I\'m running Mac OS 10.6.8. and wanted to install in addition to python 2.6 also python 2.7 and use python 2.7 in a new virtualenv. I executed the following steps:
I
I just had to make sure that /usr/local/bin/python existed.
For me it was a simple:
ln -s /usr/local/bin/python2.7 /usr/local/bin/python
There are a number of things that can cause this error. If your environment is
python3
installed from epel-release
pip3
installed with python3.4 get-pip.py
virtualenvwrapper
installed with pip3
mkvirtualenv -p /usr/bin/python3.4
Then, for whatever reason, the virtual environment is created without the virtualenvwrapper library. You can solve it by simply installing it again, but this time from within the virtlualenv
[user@localhost ~] $ mkvirtualenv -p /usr/bin/python3.4 venv
Using base prefix '/usr'
New python executable in /home/user/.virtualenvs/venv/bin/python3.4
Also creating executable in /home/user/.virtualenvs/venv/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/preactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/postactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/venv/bin/get_env_details
/home/user/.virtualenvs/venv/bin/python3.4: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: No module named 'virtualenvwrapper')
/home/user/.virtualenvs/venv/bin/python3.4: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: No module named 'virtualenvwrapper')
# the virtualenv should now activated
(venv)[user@localhost ~] $ pip install virtualenvwrapper
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
I had the same problem as this one and spent so much time on configuring out what was wrong. And I finally found out what was wrong.
First I looked for where virtualenvwrapper folder exists. In my case /usr/local/lib/python3.7/site-packages. Inside the folder is hook_loader.py that caused the error.
Next, I used python script.
python3
import sys;print('\n'.join(sys.path))
I couldn't find the /usr/local/lib/python3.7/site-packages directory so, at last I wrote,
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages
to .bashrc file. Done.
Meaning of PYTHON PATH
As you can see in above link, PYTHONPATH augment the default search path for modules.
Ran into a similar issue after installing Conda/Anaconda project. This question was quite helpful in resolving my issue on MAC.Resolving the issue had my .zshrc
relevant portion looking like this:
export VIRTUALENVWRAPPER_PYTHON=$HOME/Applications/conda/bin/python
source $HOME/Applications/conda/bin/virtualenvwrapper.sh
This is depended on where I have conda installed and you'll have to figure that in your own case. To get the specifics for your given environment depending on where you've installed anaconda you can use the following:
$ ~/ -name virtualenvwrapper.sh # to see where you have this. May already be prefilled in your shell profile[.zshrc or .profile]
$ which python # to know the default python your project or rather where conda has installed python for you
DON'T FORGET TO UNINSTALL AND INSTALL virtualenv and virtualenvwrapper as highlighted in other answers.
For anyone using Ubuntu 18.04 and Python 3+, this did the trick for me:
which python3 # outputs /usr/bin/python3
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source `which virtualenvwrapper.sh`