安装了 virtualenv 和 virtualenvwrapper:Python 说没有名为 virtualenvwrapper 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23997403/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:48:07  来源:igfitidea点击:

Installed virtualenv and virtualenvwrapper: Python says no module named virtualenvwrapper

pythonmacosvirtualenvvirtualenvwrapper

提问by user3699754

Lots of other threads about similar issues, but none that I could find where quite the same case as mine. So, here goes:

关于类似问题的许多其他主题,但我找不到与我完全相同的案例。所以,这里是:

Things I did:

我做的事情:

  • Ran: sudo easy_install pip
  • Ran: sudo pip install virtualenv
  • Ran: sudo pip install virtualenvwrapper
  • 冉: sudo easy_install pip
  • 冉: sudo pip install virtualenv
  • 冉: sudo pip install virtualenvwrapper

Current State:

当前状态:

  • .bash_profile

    export PATH=/usr/local/bin:$PATH
    export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
    export WORKON_HOME=$HOME/.virtualenvs
    export PIP_VIRTUALENV_BASE=$WORKON_HOME
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
    
  • Running mkvirtualenv testresults in:

    New python executable in trunk/bin/python
    Installing setuptools, pip...done.
    /usr/bin/python: No module named virtualenvwrapper
    
  • Manually inspecting '/usr/local/bin' shows that virtualenvwrapper.sh exists

  • Unlike some other questions I saw about this, I get no message about virtualenvwrapper when I start a new terminal window
  • Running 'which python' results in: /usr/bin/python
  • .bash_profile

    export PATH=/usr/local/bin:$PATH
    export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
    export WORKON_HOME=$HOME/.virtualenvs
    export PIP_VIRTUALENV_BASE=$WORKON_HOME
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
    
  • 运行mkvirtualenv test结果:

    New python executable in trunk/bin/python
    Installing setuptools, pip...done.
    /usr/bin/python: No module named virtualenvwrapper
    
  • 手动检查 '/usr/local/bin' 显示 virtualenvwrapper.sh 存在

  • 与我看到的其他一些问题不同,当我启动一个新的终端窗口时,我没有收到关于 virtualenvwrapper 的消息
  • 运行 'which python' 结果: /usr/bin/python

What I've tried:

我试过的:

  • Inspecting my path to make sure it looks like it is supposed to
  • Reinstalling pip, then using the reinstalled pip to reinstall virtualenv and virtualenvwrapper
  • 检查我的路径以确保它看起来应该是
  • 重新安装pip,然后使用重新安装的pip重新安装virtualenv和virtualenvwrapper

Any help getting this working would be very much appreciated.

非常感谢任何帮助使其正常工作。

回答by user3418052

I've managed to get this working after having the same problem you've described here by editing my ~/.bash_profileand adding this:

通过编辑我的~/.bash_profile并添加以下内容,在遇到您在此处描述的相同问题后,我设法使其正常工作:

export WORKON_HOME=$HOME/code/.virtualenvs
export PROJECT_HOME=$HOME/code
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'

source /usr/local/bin/virtualenvwrapper.sh

Save, close.

保存,关闭。

then:

然后:

$ source ~/.bash_profile

and:

和:

$ mkvirtualenv test

回答by manilaT

Try to uninstall your virtualenvand virtualenvwrapperand install it again using pip(check if you symlink your pip or assigned an alias on it for other version) in version 2.7 (I think).

尝试卸载您的virtualenvvirtualenvwrapper使用pip2.7 版(我认为)中的(检查您是否符号链接您的 pip 或为其分配了其他版本的别名)重新安装它。

I encountered the same error and I just did this and solved my problem.

我遇到了同样的错误,我只是这样做并解决了我的问题。

I using Ubuntu machine.

我使用 Ubuntu 机器。

I hope this help.

我希望这会有所帮助。

回答by pecai

In my case, adding this line into my .zshrc file did the trick,

就我而言,将这一行添加到我的 .zshrc 文件中就行了,

export VIRTUALENVWRAPPER_PYTHON=/usr/local/Cellar/python/2.7.13/bin/python2.7

remember to source ~/.zshrc to update the change to your current terminal.

请记住 source ~/.zshrc 以更新对当前终端的更改。

回答by asem bused

try installing virtualenv and virtualenvwrapper with pip2 install virtualenv virtualenvwrapper. it seems like pip install virtualenv and it's wrapper to python 3 as it's default

尝试安装 virtualenv 和 virtualenvwrapper pip2 install virtualenv virtualenvwrapper。看起来像 pip install virtualenv 并且它是 python 3 的包装器,因为它是默认的

回答by clyton dantis

I had the same problem setting up virtualenvwrapper on ubuntu.

我在 ubuntu 上设置 virtualenvwrapper 时遇到了同样的问题。

I had installed virtualenv, virtualenvwrapper using pip which installed these modules in the site package of python3.5. How did I find that out?

我已经使用pip安装了virtualenv,virtualenvwrapper,它们将这些模块安装在python3.5的站点包中。我是怎么发现的?

Open your terminal and type

打开你的终端并输入

$ pip --version

pip 9.0.1 from /home/clyton/.virtualenvs/test1/lib/python3.5/site-packages (python 3.5)

来自 /home/clyton/.virtualenvs/test1/lib/python3.5/site-packages (python 3.5) 的 pip 9.0.1

Then I checked the variable VIRTUALENVWRAPPER_PYTHONwhose value was /usr/bin/python. On your terminal and type

然后我检查了VIRTUALENVWRAPPER_PYTHON值为 /usr/bin/python的变量。在您的终端上输入

$ ls -l $VIRTUALENVWRAPPER_PYTHON

lrwxrwxrwx 1 root root 9 Dec 10  2015 **/usr/bin/python -> python2.7**

As you can see this variable is pointing to python2.7 and you may have installed virtualenv in a different python site package.

正如你所看到的,这个变量指向 python2.7,你可能已经在不同的 python 站点包中安装了 virtualenv。

So to fix this problem, just add the below line in your bashrc

因此,要解决此问题,只需在 bashrc 中添加以下行

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.5

NOTE:Set the above value to the python version with which virtualenv was installed. In my case it was python3.5 so I have set that value. How to find out the python version used to install virtualenv? Again type pip --versionin the terminal.

注意:将上述值设置为安装 virtualenv 的 python 版本。就我而言,它是 python3.5,所以我设置了该值。如何找出用于安装virtualenv的python版本?再次输入pip --version终端。

Then open a new shell session and try mkvirtualenv again. This time it should work.

然后打开一个新的 shell 会话并再次尝试 mkvirtualenv。这次应该可以了。

回答by wulfgarpro

If you take a look at the virtualenvwrapper.shscript, you will find these lines:

如果您查看virtualenvwrapper.sh脚本,您会发现以下行:

# Locate the global Python where virtualenvwrapper is installed.
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] 
then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
fi

If you don't manually export VIRTUALENVWRAPPERappropriately for your version of python, it will assume the system default where you don't have the virtualenvwrapperpackage installed.

如果您没有VIRTUALENVWRAPPER为您的 python 版本适当地手动导出,它将假定您没有安装virtualenvwrapper包的系统默认值。

I fixed this like so:

我是这样修复的:

echo "export VIRTUALENVWRAPPER_PYTHON=$(which python3.6)" >> ~/.zshrc

This is all documented on the official website here.

这是所有记录在官方网站上这里

回答by bjorgvin

Got this error after recently (summer 2017) updating Homebrew and python. The issue in my case was that Homebrew no longer overwrites the system python and I didn't have virtualenvand virtualenvwrapperinstalled for the system python.

最近(2017 年夏季)更新 Homebrew 和 python 后出现此错误。在我的情况下,问题是 Homebrew 不再覆盖系统 python 并且我没有virtualenvvirtualenvwrapper为系统 python 安装。

The solution in my case was to add the following to ~/.bash_profile(or ~/.zshrc):

在我的情况下的解决方案是将以下内容添加到~/.bash_profile(或 ~/.zshrc):

export PATH="$(brew --prefix)/opt/python/libexec/bin:$PATH"

export PATH="$(brew --prefix)/opt/python/libexec/bin:$PATH"

This made pythonpoint to the brew version of python and also gave me pipback. This version of pythonhad virtualenvand virtualenvwrapperinstalled so the error no longer appeared. See the caveats section under brew info pythonand https://github.com/Homebrew/homebrew-core/issues/15746for more information

python指向了 python 的 brew 版本,也给了我pip回来。这个版本的pythonvirtualenvvirtualenvwrapper安装这样的错误不再出现。见警告部分下brew info pythonhttps://github.com/Homebrew/homebrew-core/issues/15746了解更多信息

回答by abe312

I don't know if it's relevant to anyone but I got this error while editing ~/.zshrcwhile virtualenv being active. So I had to deactivateand then rmvirtualenv env_nameto remove the errors. And then I recreated the env: mkvirtaulenv env_nameand workon env_nameand this time I got no errors.

我不知道它是否与任何人有关,但是~/.zshrc在 virtualenv 处于活动状态时进行编辑时出现此错误。所以我不得不deactivate然后rmvirtualenv env_name删除错误。然后我重新创建ENV:mkvirtaulenv env_nameworkon env_name,这一次我没有错误。

Hope it helps someone.

希望它可以帮助某人。