# Require pip to install packages in virtual environment

A frequently heard piece of advice in improving Python development practice is using [virtual environments](https://pydevtools.com/handbook/explanation/what-is-a-virtual-environment.md) to install dependencies. Virtual environments isolate your dependencies per project to protect you from annoying version conflicts. For context on why this matters, see [Why should I use a virtual environment?](https://pydevtools.com/handbook/explanation/why-should-i-use-a-virtual-environment.md)

You can restrict pip to only install in virtual environments by running

```shell
pip config set global.require-virtualenv true
```

This updates your global [pip config file](https://pip.pypa.io/en/stable/topics/configuration/#location).

If you need to install a package globally for a command line tool (like [csvkit](https://csvkit.readthedocs.io/en/latest/)), I recommend using [pipx](https://pipx.pypa.io/stable/) or [uv tool install](https://docs.astral.sh/uv/concepts/tools/). This tool creates an isolated environment for the package and puts it on your system path.
