Python pip:找不到激活的 virtualenv(必需)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16460313/
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
pip: Could not find an activated virtualenv (required)
提问by Pietro Speroni
I am trying to instal virtualenv and/or virtualenvwrapper on a mac osx 10.8.3
我正在尝试在 mac osx 10.8.3 上安装 virtualenv 和/或 virtualenvwrapper
I have been fighting with python for the last two days. Finally I was able to install python 2.7.4 using brew. Before I had virtualenv installed using easy_install. Then I tried to uninstall it, trying to get my computer in the same situation as the one of my colleagues. Maybe I uninstalled it with success, maybe not. I don't know how to test it. Now I am supposed to install virtualenv using -
最近两天我一直在和python战斗。最后我能够使用 brew 安装 python 2.7.4。在我使用 easy_install 安装 virtualenv 之前。然后我尝试卸载它,试图让我的电脑和我的一位同事处于相同的情况。也许我成功卸载了它,也许没有。我不知道如何测试它。现在我应该使用 - 安装 virtualenv
pip install virtualenv
But it gives me -
但它给了我 -
Could not find an activated virtualenv (required).
pip install virtualenvwrappergives exactly the same output.
pip install virtualenvwrapper给出完全相同的输出。
Also the variable: PIP_RESPECT_VIRTUALENVis null:
还有变量:PIP_RESPECT_VIRTUALENV为空:
echo $PIP_RESPECT_VIRTUALENV
How can I solve this issue?
我该如何解决这个问题?
Thanks
谢谢
采纳答案by Bibhas Debnath
Open your ~/.bashrcfile and see if this line is there -
打开您的~/.bashrc文件,看看是否有这一行 -
export PIP_REQUIRE_VIRTUALENV=true
It might be causing the trouble. If it's there, change it to falseand run -
它可能会导致麻烦。如果它在那里,请将其更改为false并运行 -
source ~/.bashrc
If not, run export PIP_REQUIRE_VIRTUALENV=falsefrom terminal.
如果没有,请export PIP_REQUIRE_VIRTUALENV=false从终端运行。
Note: everything works the same if you have .bash_profileinstead of .bashrcin your current user's root directory.
注意:如果您在当前用户的根目录中使用.bash_profile而不是,则一切都相同.bashrc。
回答by JCotton
@Bibhas has it; +1 to look for export PIP_REQUIRE_VIRTUALENV=truein ~/.profileor ~/.bashrc. You can confirm the setting in your current shell with env |grep PIP_REQUIRE_VIRTUALENV.
@Bibhas 有;+1export PIP_REQUIRE_VIRTUALENV=true在~/.profile或 中寻找~/.bashrc。您可以使用 确认当前 shell 中的设置env |grep PIP_REQUIRE_VIRTUALENV。
This setting is a good safety check; more often than not, you'll want to be installing things into virtualenvs. However, sometimes you dowant to be working with the global/system python. In those cases, take a look at --isolated:
这个设置是一个很好的安全检查;通常情况下,您会希望将东西安装到 virtualenvs 中。但是,有时您确实希望使用全局/系统 python。在这些情况下,请查看--isolated:
Run pip in an isolated mode, ignoring environment variables and user configuration.
在隔离模式下运行 pip,忽略环境变量和用户配置。
$ pip install --upgrade pip
Could not find an activated virtualenv (required).
$ pip install --upgrade pip --isolated
Requirement already up-to-date: pip in /usr/local/lib/python2.7/site-packages
$ pip freeze --isolated
...
回答by PerryAJ
An additional solution to those already presented is to add a shell command that will allow you to install py packages by temporarily overriding the default setting. Add this to your ~/.profile, ~/.bashrcor wherever you maintain your shell's exports/settings (in my case, ~/.zshrc).
对于已经提出的解决方案,另一个解决方案是添加一个 shell 命令,该命令将允许您通过临时覆盖默认设置来安装 py 包。添加到您~/.profile,~/.bashrc或任何你保持你的shell的出口/设置(在我的情况,~/.zshrc)。
syspip(){
PIP_REQUIRE_VIRTUALENV="" pip "$@"
}
With this simple addition, you can install pip packages to the system via syspip install <package>.
通过这个简单的添加,您可以通过 将 pip 包安装到系统中syspip install <package>。
回答by Vitalii
Another place where you may possibly have this "lock" is the pip.conffile. In my case I had one in my ~/Library/Application Support/pipfolder and forgot about it.
您可能拥有此“锁定”的另一个地方是pip.conf文件。就我而言,我的~/Library/Application Support/pip文件夹中有一个,但忘记了。
Typical content of the file could be:
该文件的典型内容可能是:
[install]
require-virtualenv = true
[uninstall]
require-virtualenv = true
Similar to other answers, falseshould be changed to truein the file.
与其他答案类似,false应true在文件中更改为。
回答by N N K Teja
Verify contents of ~/.pip/pip.conf like:
验证 ~/.pip/pip.conf 的内容,如:
[global]
index=https://pypi.python.org/simple/
require-virtualenv=false
if previous it was set like require-virtualenv=true
如果以前设置为 require-virtualenv=true
回答by Roberto Font
for matchbook you must go to '.bash_profile '
对于火柴盒,您必须转到“.bash_profile”
1) open with your favorite editor in terminal
1)在终端中用你最喜欢的编辑器打开
nano .bash_profile OR vim .bash_profile
nano .bash_profile 或 vim .bash_profile
2) find the text line that says
2)找到说的文本行
export PIP_REQUIRE_VIRTUALENV=true
导出 PIP_REQUIRE_VIRTUALENV=true
3) delete it or set it equal to "false"
3)删除它或将其设置为“false”
4) finally restart your terminal
4)最后重启你的终端
回答by Micah
Important to heed @JCotton's advice here-- keeping your pip setup so as to only install into virtualenvs is a great practice.
重要的是要注意 @JCotton 在这里的建议——保持你的 pip 设置以便只安装到 virtualenvs 中是一个很好的做法。
His solution to get virtualenv setup again of pip install --upgrade pip --isolatedis exactly what should be done.
他重新设置 virtualenv 的解决方案pip install --upgrade pip --isolated正是应该做的。
You should NOT turn off requiring a virtualenv, either by config file or by editing ~/.bash_rc or ~/.bash_profile, to get your project's pip packages installed. We're only doing it here because OP needs virtualenv itself installed.
您不应该通过配置文件或编辑 ~/.bash_rc 或 ~/.bash_profile 来关闭需要 virtualenv 来安装项目的 pip 包。我们只是在这里这样做,因为 OP 需要安装 virtualenv 本身。
In general, I see people get this message when their virtualenv wasn't setup correctly for their project in the first place. Reminder that to create a virtualenv with its own python and pip so that you don't run into the "could not find an activated virtualenv" error, you run virtualenv -p python3
一般来说,我看到人们在最初没有为他们的项目正确设置他们的 virtualenv 时收到此消息。提醒要使用自己的 python 和 pip 创建 virtualenv,以免遇到“找不到激活的 virtualenv”错误,请运行virtualenv -p python3

