pip: Could not find an activated virtualenv (required)
Solution 1
Open your ~/.bashrc
file and see if this line is there -
export PIP_REQUIRE_VIRTUALENV=true
It might be causing the trouble. If it's there, change it to false
and run -
source ~/.bashrc
If not, run export PIP_REQUIRE_VIRTUALENV=false
from terminal.
Note: everything works the same if you have .bash_profile
instead of .bashrc
in your current user's root directory.
Solution 2
@Bibhas has it; +1 to look for export PIP_REQUIRE_VIRTUALENV=true
in ~/.profile
or ~/.bashrc
. You can confirm the setting in your current shell with 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 do want to be working with the global/system python. In those cases, take a look at --isolated:
Run pip in an isolated mode, ignoring environment variables and user configuration.
$ 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
...
Solution 3
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
, ~/.bashrc
or wherever you maintain your shell's exports/settings (in my case, ~/.zshrc
).
syspip(){
PIP_REQUIRE_VIRTUALENV="" pip "$@"
}
With this simple addition, you can install pip packages to the system via syspip install <package>
.
Solution 4
Verify contents of ~/.pip/pip.conf like:
[global]
index=https://pypi.python.org/simple/
require-virtualenv=false
if previous it was set like require-virtualenv=true
Solution 5
Another place where you may possibly have this "lock" is the pip.conf
file. In my case I had one in my ~/Library/Application Support/pip
folder and forgot about it.
Typical content of the file could be:
[install]
require-virtualenv = true
[uninstall]
require-virtualenv = true
Similar to other answers, false
should be changed to true
in the file.
Comments
-
amg over 3 years
I am trying to instal virtualenv and/or virtualenvwrapper on a mac osx 10.8.3
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 -
pip install virtualenv
But it gives me -
Could not find an activated virtualenv (required).
pip install virtualenvwrapper
gives exactly the same output.Also the variable:
PIP_RESPECT_VIRTUALENV
is null:echo $PIP_RESPECT_VIRTUALENV
How can I solve this issue?
Thanks
-
amg almost 11 yearsIndeed the line export PIP_RESPECT_VIRTUALENV=true was there. So I commented it. Then source run the file again, but it would still not work. So I opened a new terminal, and now it worked. Thank you VERY much.
-
cbron about 10 yearsYea, it has to be set to false for me.
-
Admin over 9 yearsFor anyone else coming across this: Please note the difference between
PIP_RESPECT_VIRTUALENV
(as mentioned in the original question) andPIP_REQUIRE_VIRTUALENV
, which is the solution mentioned above. -
JeremyDouglass almost 6 yearsTrouble leading to this error could also be called by other settings in
.bashrc
, such asVIRTUALENVWRAPPER_PYTHON
. Runningexport PIP_REQUIRE_VIRTUALENV=false
and then a pip uninstall / install virtualenv worked in my case. -
Eir Nym over 5 yearsalso this file could be found at
~/.pip/pip.conf
-
Robson about 5 yearsHow this is different from the currently accepted solution?
-
Roberto Font about 5 yearsWell it’s on a different file that’s why I post it. Because with the guide here I could not find it
-
JGurtz over 3 yearsWould appreciate a canonical link to the mentioned advice. I generally agree with virtualenv being a good idea for writing applications. There are times when one is not writing a "project"*. It's a one-liner, say, or some small, throwaway test cases. Virtualenv is just annoying and impedes in these cases, particularly when things like pyyaml are not there by default. But, maybe I'm doing it wrong? Always looking to upgrade my knowledge.
-
JGurtz over 3 yearsSee also the other answer about
~/.pip/pip.conf
. The environment will override the pip.conf setting, but maybe it's better to change it at the source if you need to change the behavior.