更新后 python 和 virtualenvwrapper 的问题:没有名为 virtualenvwrapper 的模块

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

problems with python and virtualenvwrapper after updating: No module named virtualenvwrapper

pythonvirtualenvvirtualenvwrapper

提问by mthecreator

I run python 2.7.6 with virtualenv, virtualenvwrapper under ubuntu 14.04. now i have installed python 2.7.9 from source. the new python interpreter is now located under /usr/local/binbut it seems the old interpreter is also located under /usr/bin.

我在 ubuntu 14.04 下使用 virtualenv、virtualenvwrapper 运行 python 2.7.6。现在我已经从源代码安装了 python 2.7.9。新的Python解释器现在位于下/usr/local/bin,但它似乎老解释也位于下/usr/bin

if I run python shell it shows up python2.7.9. but if I use mkvirtualenv venvI am getting the following message.

如果我运行 python shell,它会显示 python2.7.9。但如果我使用,mkvirtualenv venv我会收到以下消息。

New python executable in venv/bin/python
Installing setuptools, pip...done.
Blockquote /usr/local/bin/python: No module named virtualenvwrapper

venv/bin/python 中的新 python 可执行文件
安装 setuptools,pip...完成。
Blockquote /usr/local/bin/python: 没有名为 virtualenvwrapper 的模块

old .bashrc(with working configuration using python 2.7.6 interpreter)

旧的.bashrc(使用 python 2.7.6 解释器的工作配置)

# virtualenv-wrappper path
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

new .bashrc(with failure configuration)

新的.bashrc(带有故障配置)

# virtualenv-wrappper path
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

with the new .baschrcI type in source .bashrcand get the following output.

使用新的.baschrcI 输入source .bashrc并获得以下输出。

/usr/local/bin/python: 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/python and that PATH is set properly.

/usr/local/bin/python:没有名为 virtualenvwrapper 的模块 virtualenvwrapper.sh:运行初始化挂钩时出现问题。

如果 Python 无法导入模块 virtualenvwrapper.hook_loader,请检查是否已为 VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python 安装了 virtualenvwrapper,并且 PATH 设置是否正确。

And I have also tried which -a python:

我也试过which -a python

output:

输出:

/usr/local/bin/python
/usr/bin/python

I want to use python 2.7.9 with virtualenv and virtualenvwrapper. so what I have to do to get this running ?

我想将 python 2.7.9 与 virtualenv 和 virtualenvwrapper 一起使用。所以我必须做些什么才能让它运行?

采纳答案by Railslide

You need to install them under python 2.7.9 by specifying the path to correct version of pip to be used

您需要通过指定要使用的正确 pip 版本的路径将它们安装在 python 2.7.9 下

/usr/local/bin/pip install virtualenv virtualenvwrapper

otherwise, when running pip installthe sytem will use the default one (i.e. the one located at /usr/bin/pip)

否则,在运行pip install系统时将使用默认的(即位于/usr/bin/pip

回答by Sudipta Basak

If you have modified your virtualenvwrapperto point to python3, like I do:

如果您修改virtualenvwrapper了指向python3,就像我一样:

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

then make sure you install the virtualenvand virtualenvwrapperusing:

然后确保安装virtualenvvirtualenvwrapper使用:

sudo /usr/local/bin/pip3 install virtualenv virtualenvwrapper

回答by likaiguo.happy

source /usr/local/bin/virtualenvwrapper_lazy.sh

source /usr/local/bin/virtualenvwrapper_lazy.sh



when use pyenv:

使用 pyenv 时:

export PYENV_ROOT="${HOME}/.pyenv"

if [ -d "${PYENV_ROOT}" ]; then
    export PATH="${PYENV_ROOT}/bin:${PATH}"
    eval "$(pyenv init -)"
fi
export PATH

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
#important
source /usr/local/bin/virtualenvwrapper_lazy.sh