[英]/usr/bin/python3: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: No module named 'virtualenvwrapper')
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!我正在尝试在 Ubuntu 14.04 上关注如何使用 uWSGI 和 Nginx 服务 Django 应用程序,由于 output 的数量,我在很早的阶段就失败了,我将所有相关信息放入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?我正在关注如何刷牙,我做错了什么?
Thanks to @Alexander, I was able to fix my issue by changing the line in ~/.bashrc
:感谢@Alexander,我能够通过更改
~/.bashrc
的行来解决我的问题:
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
to到
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
due to backwards compatibility.由于向后兼容。
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
I encountered a similar issue with virtualenvwrapper
complaining not being to find virtualenvwrapper.hook_loader
.我遇到了一个与
virtualenvwrapper
类似的问题,抱怨没有找到virtualenvwrapper.hook_loader
。 I was able to narrow down to this particular line in my .bash_profile
我能够在我的
.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.经过一些试验和错误,结果是重新安装
virtualenvwrapper
包解决了它。 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).这是我最近通过自制软件升级 python3(从 3.5.2 版到 3.6.1 版)这一事实的证明,反过来它破坏了 virtualenvwrapper 的 shell 脚本,该脚本对旧版本的 python3 的引用进行了硬编码(在我的情况下是 3.5。 2)。 In short, this below line should fix it (at least in my case it did).
简而言之,下面这行应该修复它(至少在我的情况下是这样)。
pip3 install virtualenvwrapper
我已经安装了 virtualenv 所以只需要运行
pip3 install virtualenvwrapper
In macOS Sierra, If you installed virtualenv
package using pip3
, add following to .bash_profile
在 macOS Sierra 中,如果您使用
pip3
安装了virtualenv
包,请将以下内容添加到.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
创建的每个新workon myvenv
使用python3
作为 python 解释器
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并注销和登录
check your python3
installation directory:检查你的
python3
安装目录:
which python3
If installed by brew you should get:如果通过brew安装,你应该得到:
/usr/local/python3
export python version to be used virtualenvwrapper:要使用 virtualenvwrapper 的导出 python 版本:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/python3
source your shell configuration file:获取你的 shell 配置文件:
bash猛击
source .bashrc
zsh zsh
source .zshrc
In my case, there was somehow a mismatch between pip3 and python3 (because I have multiple pythons installed).就我而言,pip3 和 python3 之间存在某种不匹配(因为我安装了多个 python)。 This worked for me:
这对我有用:
sudo python -m pip install virtualenvwrapper
This error appeared for me after running brew update
and brew upgrade
on mac os high sierra.在 mac os high sierra 上运行
brew update
和brew upgrade
后,我出现了这个错误。
The issue was resolved by reinstalling virtualenvwrappper ie pip install virtualenvwrapper
.该问题已通过重新安装 virtualenvwrappper 解决,即
pip install virtualenvwrapper
。
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).因此,就我而言,事实证明我的脚本在我已经在虚拟环境中时试图激活它(
workon
语句是从我的.profile
文件中发出的)。 And so the solution was to simply deactivate
the environment first and then run the script.所以解决方案是简单地先
deactivate
环境,然后运行脚本。
If you're here after a macOS update, and installed python3 via brew, try re-linking your version of python3如果您在 macOS 更新后来到这里,并通过 brew 安装了 python3,请尝试重新链接您的 python3 版本
brew link python@3.8
brew link python@3.9
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 作为我的默认值
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:在我的
.bashrc
我写道:
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
注意:如果激活环境并运行
which python3
,您会发现 python run 是环境之一,而不是VIRTUALENVWRAPPER_PYTHON
指定的全局环境
I had this warning after a brew upgrade, which updated python3 packages and brew-installed python3.我在 brew 升级后收到了这个警告,它更新了 python3 包和 brew 安装的 python3。
I found a pip3 and python3 version mismatch as Evan Thomas hinted :我发现 pip3 和 python3 版本不匹配,正如 Evan Thomas 所暗示的:
❯ 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.运行
brew link python@3.9
作为snakesNbronies 建议删除警告。
I found that problem can be reproduced with or without pyenv.我发现使用或不使用 pyenv 都可以重现该问题。 Here checklist how to solve this problem which helps me on Mac with fresh install brew and pyenv:
这里列出了如何解决这个问题,这有助于我在 Mac 上全新安装 brew 和 pyenv:
pyenv install 3.11.1
(or whatever version you need) and global it with command pyenv global 3.11.1
pyenv install 3.11.1
(或你需要的任何版本)并使用命令pyenv global 3.11.1
将其全局化python
and make sure, that it's the same version that you set-up in previous step.python
并确保它与您在上一步中设置的版本相同。python -m pip install virtualenv virtualenvwrapper
python -m pip install virtualenv virtualenvwrapper
which python
tells you python path to your installed path. which python
告诉您安装路径的 python 路径。 Use this path to selected by system python executable to tell virtualenvwrapper
which python it need to use with variable VIRTUALENVWRAPPER_PYTHON
.virtualenvwrapper
它需要使用变量VIRTUALENVWRAPPER_PYTHON
哪个 python 。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
I had a similar issue on Mac OS Catalina 10.15.6 after I installed vim
and macvim
using following:使用以下方法安装
vim
和macvim
后,我在 Mac OS Catalina 10.15.6 上遇到了类似的问题:
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
工作但总是给出如下错误消息:
~ $ 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:最终对我有用的是:
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
to .bash_profile
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
到.bash_profile
sudo pip3 install virtualenvwrapper
try to install python-is-python3:尝试安装 python-is-python3:
1.Update the package index: 1.更新包索引:
sudo apt-get update
2.Install python-is-python3 deb package: 2.安装python-is-python3 deb包:
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.如果有人仍然遇到此问题,我按照此线程上的最佳答案修复了与我的 python 版本不匹配的 pip3,然后运行
sudo pip3 install virtualenv virtualenvwrapper
后跟source ~/.bashrc
为我解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.