Monday, July 11, 2022

[SOLVED] Disable global installs using pip - allow only virtualenvs

Issue

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 big fat warning when using it this way to make sure that I know what am I 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

This gives you exactly what you want, example:

$ pip install foobar
ERROR: Could not find an activated virtualenv (required).


Answered By - akhomchenko
Answer Checked By - Cary Denson (WPSolving Admin)