/usr/bin/python3: 在查找‘ viralenvwrapper.hook_loader’规范时出错(< class‘ Import Error’> : No module name‘ viralenvwrapper’)

我试图跟随 如何在 Ubuntu 14.04上使用 uWSGI 和 Nginx 服务 Django 应用程序,但是在很早的阶段就失败了,由于输出量的原因,我把所有相关的信息都放到了 Pastebin.com-自2002年以来的第一粘贴工具!中。

实际的错误:

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:~#

我正在学习如何咬牙切齿,我做错了什么?

101215 次浏览

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.

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

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

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

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

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

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.

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

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'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.

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:

  1. adding export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 to .bash_profile
  2. sudo pip3 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

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 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

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.

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.