Require pip to install packages in virtual environment

Require pip to install packages in virtual environment

March 4, 2024

A frequently heard piece of advice in improving Python development practice is using virtual environments to install dependencies. Virtual environments isolate your dependencies per project to protect you from annoying version conflicts.

You can restrict pip to only install in virtual environments by creating a pip config file and setting:

[global]
require-virtualenv = True

Mac and Linux users can put this config in $HOME/.config/pip/pip.conf and Windows users in %APPDATA%\pip\pip.ini.

If you need to install a package globally for a command line tool (like csvkit), I recommend using pipx. This tool creates an isolated environment for the package and puts it on your system path.

Last updated on

Please submit corrections and feedback...