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
To install virtualenv, just use pip install virtualenv . To create a virtual environment directory with it, type virtualenv /path/to/directory . Activating and deactivating the virtual environment works the same way as it does for virtual environments in Python 3 (see above).
pip is a tool for installing packages from the Python Package Index. virtualenv is a tool for creating isolated Python environments containing their own copy of python , pip , and their own place to keep libraries installed from PyPI.
In order to make sure that you install packages to your active virtual environment when you use pip install, consider adding the following line to your ~/.bashrc file: After saving this change and sourcing the ~/.bashrc file with source ~/.bashrc, pip will no longer let you install packages if you are not in a virtual environment.
When using older versions, you can configure pip in such a way that it tries to reuse already installed packages, too. On Unix systems, you can add the following line to your .bashrc or .bash_profile file. You can set the path to anywhere you like (as long as you have write access).
You can also do this configuration by editing your pip.conf or pip.ini file. pip.conf is used by Unix and Mac OS X operating systems and it can be found at: $ HOME/.pip/pip.conf. Similarly, the pip.ini file is used by Windows operating systems and it can be found at: % USERPROFILE% \p ip \p ip.ini.
Similarly, the pip.ini file is used by Windows operating systems and it can be found at: % USERPROFILE% \p ip \p ip.ini. If you don’t have a pip.conf or pip.ini file at these locations, you can create a new file with the correct name for your operating system.
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.
@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
...
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>
.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With