# Require pip to install packages in virtual environment

A frequently heard piece of advice in improving Python development practice is using [virtual environments](https://docs.python.org/3/library/venv.html) 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 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.
