Search code examples
pythonpipvirtualenv

Disable global installs using pip - allow only virtualenvs


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?


Solution

  • I can be late, but you can do it either via:

    1. config (~/.pip/pip.conf):
    [global]
    require-virtualenv = true
    
    1. env variable PIP_REQUIRE_VIRTUALENV

    2. 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).