简体   繁体   English

/usr/bin/python3:查找“virtualenvwrapper.hook_loader”规范时出错(<class 'importerror'> : 没有名为“virtualenvwrapper”的模块)</class>

[英]/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 updatebrew 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
  • 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:在我的电脑上,我运行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:

  1. 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将其全局化
  2. type python and make sure, that it's the same version that you set-up in previous step.输入python并确保它与您在上一步中设置的版本相同。
  3. install virtualenvwrapper with python -m pip install virtualenv virtualenvwrapper使用python -m pip install virtualenv virtualenvwrapper
  4. FIRST IMPORTANT!首先重要! SET THE FIRST VARIABLE CORRECT!正确设置第一个变量! 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 .使用此路径由系统 python 可执行文件选择,以告诉virtualenvwrapper它需要使用变量VIRTUALENVWRAPPER_PYTHON哪个 python 。
  5. SECOND IMPORTANT.第二重要。 Make sure you execute correct virtualenvwrapper.sh.确保执行正确的 virtualenvwrapper.sh。 I use pyenv so I just use virtualenvwrapper in my global version (look for config below)我使用 pyenv,所以我只在我的全局版本中使用 virtualenvwrapper(在下面查找配置)
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:使用以下方法安装vimmacvim后,我在 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:最终对我有用的是:

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

相关问题 Python Virtualenv - 没有名为virtualenvwrapper.hook_loader的模块 - Python Virtualenv - No module named virtualenvwrapper.hook_loader 当我将 python3.7 降级到 python3.6 时,查找“virtualenvwrapper.hook_loader”的模块规范时出错 - Error while finding module specification for 'virtualenvwrapper.hook_loader' when I downgrade python3.7 to python3.6 无法导入模块virtualenvwrapper.hook_loader - Cannot import module virtualenvwrapper.hook_loader Python 无法导入模块 virtualenvwrapper.hook_loader? - Python could not import the module virtualenvwrapper.hook_loader? ImportError:没有名为“ virtualenvwrapper”的模块 - ImportError: No module named 'virtualenvwrapper' Virtualenvwrapper:没有名为virtualenvwrapper的模块 - Virtualenvwrapper: no module named virtualenvwrapper 将Python3传递给virtualenvwrapper会引发ImportError - Passing Python3 to virtualenvwrapper throws up ImportError 更新后 python 和 virtualenvwrapper 的问题:没有名为 virtualenvwrapper 的模块 - problems with python and virtualenvwrapper after updating: No module named virtualenvwrapper 安装了 virtualenv 和 virtualenvwrapper:Python 说没有名为 virtualenvwrapper 的模块 - Installed virtualenv and virtualenvwrapper: Python says no module named virtualenvwrapper /usr/bin/python3: 没有名为 pytest 的模块 - /usr/bin/python3: No module named pytest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM