Reputation: 6940
Sometimes by mistake, I install some packages globally with plain pip install package
and contaminate my system instead of creating a proper virtualenv and keeping things tidy.
How can I easily disable global installs with pip
at all?
Or at least show a big warning when using it this way to ensure I know what I am doing?
Upvotes: 14
Views: 2546
Reputation: 280
I can be late, but you can do it either via:
~/.pip/pip.conf
):[global]
require-virtualenv = true
env variable PIP_REQUIRE_VIRTUALENV
For pip versions >= 10.0.0b1, from the command line system-wide using:
pip config set global.require-virtualenv true
This gives you exactly what you want, example:
$ pip install foobar
ERROR: Could not find an activated virtualenv (required).
Upvotes: 23
Reputation: 296
You could try creating adding something like this to your .bashrc
pip() {
if [ -n "$VIRTUAL_ENV" ]; then
# Run pip install
else
echo "You're not in a virtualenv"
fi
}
My knowledge of bash isn't the greatest but this should put you on the right path I think.
Upvotes: 0