/usr/bin/python3: 查找 'virtualenvwrapper.hook_loader' 规范时出错(<class 'ImportError'>:没有名为 'virtualenvwrapper' 的模块)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33216679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
/usr/bin/python3: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: No module named 'virtualenvwrapper')
提问by alexus
I'm trying to follow How To Serve Django Applications with uWSGI and Nginx on Ubuntu 14.04and 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!.
我正在尝试遵循如何在 Ubuntu 14.04 上使用 uWSGI 和 Nginx 为 Django 应用程序提供服务,但由于输出量太大,我在很早的阶段失败了,我将所有相关信息放入Pastebin.com - #1 粘贴工具,因为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?
我正在关注如何到牙齿,我做错了什么?
采纳答案by alexus
Thanks to @Alexander, I was able to fix my issue by changing:
感谢@Alexander,我能够通过更改来解决我的问题:
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
to
到
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
due to backwards compatibility.
由于向后兼容。
回答by KIYOUNG KIM
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
导出 VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
good choice, but you already knew /usr/bin/python is 2.7
不错的选择,但您已经知道 /usr/bin/python 是 2.7
If you want to use version 3
如果您想使用版本 3
sudo apt-get install python3-pip
须藤 apt-get 安装 python3-pip
and logout & login
并注销和登录
回答by Gagandeep Singh
I faced similar problem, when using python3 with virtualenvwrapper,
我遇到了类似的问题,当使用 python3 和 virtualenvwrapper 时,
sudo apt-get install python3-pip
Then install virtualenv and virtualenvwrapper from pip3,
然后从pip3安装virtualenv和virtualenvwrapper,
sudo pip3 install virtualenv virtualenvwrapper
then source it again,
然后再次来源,
source $HOME/.bashrc
回答by Devy
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
我遇到了类似的问题,virtualenvwrapper
抱怨没有找到virtualenvwrapper.hook_loader
. 我能够缩小到我的这一特定行.bash_profile
source /usr/local/bin/virtualenvwrapper.sh
源/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).
经过一些试验和错误,事实证明重新安装virtualenvwrapper
软件包解决了它。这是我最近通过自制软件升级 python3(从 3.5.2 版到 3.6.1 版)这一事实的证明,反过来它破坏了 virtualenvwrapper 的 shell 脚本,该脚本对旧版本的 python3 的引用进行了硬编码(在我的情况下是 3.5。 2)。简而言之,下面这行应该修复它(至少在我的情况下是这样)。
pip3 install virtualenvwrapper
回答by Dominic Motuka
check your python3
installation directory:
检查你的python3
安装目录:
which python3
which python3
If installed by brewyou should get:
如果通过brew安装,你应该得到:
/usr/local/python3
/usr/local/python3
export python version to be used virtualenvwrapper:
要使用 virtualenvwrapper 的导出 python 版本:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/python3
export VIRTUALENVWRAPPER_PYTHON=/usr/local/python3
source your shell configuration file:
bash
获取你的 shell 配置文件:
bash
source .bashrc
source .bashrc
zsh
zsh
source .zshrc
source .zshrc
回答by heykarimoff
In macOS Sierra,
If you installed virtualenv
package using pip3
,
add following to .bash_profile
在 macOS Sierra 中,如果您virtualenv
使用安装了软件包pip3
,请将以下内容添加到.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
以后您在使用创建的每个新的虚拟环境workon myvenv
的用途python3
为Python解释器
回答by chorbs
This error appeared for me after running brew update
and brew upgrade
on mac os high sierra.
运行后brew update
和brew upgrade
在 mac os high sierra 上出现此错误。
The issue was resolved by reinstalling virtualenvwrappper i.e. pip install virtualenvwrapper
.
该问题已通过重新安装 virtualenvwrappper ie 解决pip install virtualenvwrapper
。
回答by Matt Doran
I had already installed virtualenv so just needed to run
我已经安装了 virtualenv 所以只需要运行
pip3 install virtualenvwrapper
回答by Evan Thomas
In my case, there was somehow a mismatch between pip3 and python3 (because I have multiple pythons installed). This worked for me:
就我而言,pip3 和 python3 之间存在某种不匹配(因为我安装了多个 python)。这对我有用:
sudo python -m pip install virtualenvwrapper
回答by Tshepo Shere
On my computer, I ran sudo apt install python-pip
and then pip install virtualenvwrapper
but on my settings, I set it as follows:
在我的电脑上,我跑了sudo apt install python-pip
然后pip install virtualenvwrapper
但在我的设置中,我将其设置如下:
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
这消除了错误并注意我使用的是 python3 并且我使用 pip3 作为我的默认值