Keep getting this error when my bashrc is sourced:
/usr/bin/python: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: 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.
I have read other posts about this. Most posts state to pip3 install virtualenwrapper. This does not work.
I am using a symbolic link for /usr/bin/python -> /usr/bin/python3.10.
If I put the link back to /usr/bin/python3.8 it works.
Why wont virtualenvwrapper not work with my /usr/bin/python symbolic link to 3.10?
/usr/local/bin/virtualenvwrapper.sh is a collection of shell functions to include into shell. But there have to be a virtualenvwrapper python module installed into site-packages. You have to install it into the same python:
/usr/bin/python3.10 -m pip install virtualenwrapper
I need to install virtualenvwrapper on my macOS Sierra to be able to install TensorFlow. Previously I had installed Python 3 based on the instructions here using Homebrew.
Now pip seemed to be nonexistent (pip2 and pip3 worked though), so I did
sudo easy_install pip
Then I followed the instructions given here, and when I do
source /usr/local/bin/virtualenvwrapper.sh
I get the following error:
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.
I have tried the solutions given here, and here, but no success. I have even tried to install virtualenvwrapper with:
sudo pip2 install --upgrade virtualenvwrapper
and
sudo pip3 install --upgrade virtualenvwrapper
and still I get the same error. Could someone please help me with this issue?
EDIT:
I have tried to do lazy loading of the virtualenvwrapper like so:
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
source /usr/local/bin/virtualenvwrapper_lazy.sh
Only then I don't get any errors, and I am able to proceed with installing TensorFlow. But then every time I open a new terminal workon does not work, and I have to do source /usr/local/bin/virtualenvwrapper_lazy.sh every time to be able to use workon. Even when workon is invoked I get a warning/error message as /usr/bin/python: No module named virtualenvwrapper.
Could someone help me see what is going on here?
My solution is simply a hack and not a clean and logical way for solving this but you could edit /usr/local/bin/virtualenvwrapper.sh as root and in the section that is followed by
# Locate the global Python where virtualenvwrapper is installed.
remove the if/else condition and simply use
VIRTUALENVWRAPPER_PYTHON="$(command \which python3.5)" (Change 3.5 to your version) and then source the file again.
I am trying to learn how to program using Django, but I am stuck dealing with some problems related to the use of virtualenv and virtualenvwrapper.
I am using a Mac with the following OSX OS X El Capitan 10.11.3 with Python 2.7.10 as default.
I have just recently downloaded Python 3.5 and also virtualenv and virtualenvwrapper using the following commands in the terminal:
pip install virtualenv
pip install virtualenvwrapper
This seemed to work smoothly, and so I followed the installation guide found at Virtualenvwrapper Installation Guide in order to correctly modify the .bash_profile so that the virtualenvwrapper is loaded correctly.
However, there are some of the guidelines I do not fully understand and thus I am not able to successfully set up the virtualenvwrapper.
The following lines are said to be added to the shell startup file:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
But when I installed the virtualenvwrapper, the virtualenvwrapper.sh was stored in the following path: Library/Frameworks/Python.framework/Versions/3.5/bin/
In other words, there is no file called virtualenvwrapper.sh at /usr/local/bin/.
My shell startup file currently looks like this:
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
When I now try to write the following code in terminal:
source ~/.bash_profile
the following outputs:
-bash: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
I have also tried to change the path of the source in the .bash_profile to the following:
source Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenvwrapper.sh
which is where the virtualenvwrapper.sh file is located. This however, gives the following output:
/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.
Any suggestions as to how I should fix this? I am sorry for the length of the question, but I wanted to explain the problem thoroughly.
I would be really thankful for any answers :)
virtualenvwrapper.sh should be in your path somewhere. The simplest solution is tp change the source statement to read
source `which virtualenvwrapper.sh`
Note the back-ticks around the which virtualenvwrapper.sh part of the command.
That will find it in the path, wherever it actually lives. And yes, on a mac, it is often in Library/Frameworks/ etc. But that should be on your path because part of the install for python will put it there.
I'm trying to follow How To Serve Django Applications with uWSGI and Nginx on Ubuntu 14.04 and I'm failing at the very earlier stage, due to amount of output, I placed all related information into Pastebin.com - #1 paste tool since 2002!.
the actual error:
root#alexus:~# echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
root#alexus:~# source ~/.bashrc
/usr/bin/python3: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: 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/python3 and that PATH is
set properly.
root#alexus:~#
I'm following how to to the teeth, what am I doing wrong?
I faced similar problem, when using python3 with virtualenvwrapper,
sudo apt-get install python3-pip
Then install virtualenv and virtualenvwrapper from pip3,
sudo pip3 install virtualenv virtualenvwrapper
then source it again,
source $HOME/.bashrc
Thanks to #Alexander, I was able to fix my issue by changing the line in ~/.bashrc:
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
to
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
due to backwards compatibility.
I encountered a similar issue with virtualenvwrapper complaining not being to find virtualenvwrapper.hook_loader. I was able to narrow down to this particular line in my .bash_profile
source /usr/local/bin/virtualenvwrapper.sh
as seen below
$ source /usr/local/bin/virtualenvwrapper.sh
/usr/local/opt/python3/bin/python3.6: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: 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/python3 and that PATH is
set properly.
After some trial and error, it turns out that a reinstallation of the virtualenvwrapper package resolved it. This was a manifest of the fact that I recently upgrade python3 (from version 3.5.2 to 3.6.1) via homebrew and in turn it broke virtualenvwrapper's shell script that hardcoded references to the older version of python3 (in my case it was 3.5.2). In short, this below line should fix it (at least in my case it did).
pip3 install virtualenvwrapper
In macOS Sierra,
If you installed virtualenv package using pip3,
add following to .bash_profile
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
or
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
after that every new virtualenvironment you created using workon myvenv
uses python3 as python interpreter
I had already installed virtualenv so just needed to run
pip3 install virtualenvwrapper
In my case, there was somehow a mismatch between pip3 and python3 (because I have multiple pythons installed). This worked for me:
sudo python -m pip install virtualenvwrapper
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
good choice, but you already knew /usr/bin/python is 2.7
If you want to use version 3
sudo apt-get install python3-pip
and logout & login
check your python3 installation directory:
which python3
If installed by brew you should get:
/usr/local/python3
export python version to be used virtualenvwrapper:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/python3
source your shell configuration file:
bash
source .bashrc
zsh
source .zshrc
This error appeared for me after running brew update and brew upgrade on mac os high sierra.
The issue was resolved by reinstalling virtualenvwrappper i.e. pip install virtualenvwrapper.
Here is what for me solved
Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
obtained in creating and activating environments.
In my .bashrc I had wrote:
export VIRTUALENVWRAPPER_PYTHON=python3
Changing it to:
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
solved the problem for me.
NOTE: If you activate an environment and run which python3, you will find out that the python run is the one of the environment, not the global one specified in VIRTUALENVWRAPPER_PYTHON
I've got this error for entirely different reasons, but since I ended up on this thread, I gather somebody might find this useful. So in my case, it turned out that my script was attempting to activate the virtual environment while I was already on it (the workon statement is issued from my .profile file). And so the solution was to simply deactivate the environment first and then run the script.
If you're here after a macOS update, and installed python3 via brew, try re-linking your version of python3
brew link python#3.8
brew link python#3.9
etc
On my computer, I ran sudo apt install python-pip and then pip install virtualenvwrapper but on my settings, I set it as follows:
export WORKON_HOME=$HOME/.Envs
export VIRTUALENVWRAPPER_PYTHON=$(which -a python3)
source $HOME/.local/bin/virtualenvwrapper.sh
That got rid of the error and note that I am using python3 and I use pip3 as my default
I had this warning after a brew upgrade, which updated python3 packages and brew-installed python3.
I found a pip3 and python3 version mismatch as Evan Thomas hinted:
❯ which python3 && python3 --version
/usr/bin/python3
Python 3.8.2
❯ which pip3 && pip3 --version
/usr/local/bin/pip3
pip 21.0.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
Running brew link python#3.9 as snakesNbronies suggested removes the warning.
I had a similar issue on Mac OS Catalina 10.15.6 after I installed vim and macvim
using following:
brew install vim && brew install macvim
which I believe was the cause for the problem.
While workon worked but always gave an error message as below:
~ $ workon loom
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
(loom) ~ $
What worked for me finally was:
adding export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 to .bash_profile
sudo pip3 install virtualenvwrapper
I found that problem can be reproduced with or without pyenv.
Here checklist how to solve this problem which helps me on Mac with fresh install brew and pyenv:
pyenv install 3.11.1 (or whatever version you need) and global it with command pyenv global 3.11.1
type python and make sure, that it's the same version that you set-up in previous step.
install virtualenvwrapper with python -m pip install virtualenv virtualenvwrapper
FIRST IMPORTANT! SET THE FIRST VARIABLE CORRECT! which python tells you python path to your installed path. Use this path to selected by system python executable to tell virtualenvwrapper which python it need to use with variable VIRTUALENVWRAPPER_PYTHON.
SECOND IMPORTANT! Make sure you execute correct virtualenvwrapper.sh. I use pyenv so I just use virtualenvwrapper in my global version (look for config below)
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
export PYENV_VERSION="$(pyenv version-name)"
VIRTUALENVWRAPPER_PYTHON="$HOME/.pyenv/shims/python"
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source ~/.pyenv/versions/$PYENV_VERSION/bin/virtualenvwrapper.sh
# Tell pyenv-virtualenvwrapper to use pyenv when creating new Python environments
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
# Set the pyenv shims to initialize
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
try to install python-is-python3:
1.Update the package index:
sudo apt-get update
2.Install python-is-python3 deb package:
sudo apt-get install python-is-python3
If anyone's still having this issue, I followed the top answer on this thread to fix a pip3 mismatch with my version of python, then ran sudo pip3 install virtualenv virtualenvwrapper followed by source ~/.bashrc which resolved the issue for me.
I am working to set up a django project on ec2 with an Ubuntu 14.4 LTS instance. I want to write my code using python 3 and django. I've been advised that the best way to do this is to use virtualenvwrapper. I tried:
ubuntu:~$ sudo pip3 install virtualenvwrapper
Successfully uninstalled six
Successfully installed virtualenvwrapper virtualenv virtualenv-clone stevedore argparse pbr six
Cleaning up...
ubuntu:~$ mkvirtualenv env1
mkvirtualenv: command not found
What am I doing wrong?
edit:
I followed your directions, logged out and logged back in:
/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.
I'm suspecting that this is because I'm installing to python3 which is not the default python interpreter
From the documentation
Shell Startup File
Add three lines to your shell startup file
(.bashrc, .profile, etc.) to set the location where the virtual
environments should live, the location of your development project
directories, and the location of the script installed with this
package:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
In particular, sourcing the shell script above will allow you to run all of the virtualenvwrapper commands.