Today I Learned
Search…
Preventing global package install with `PIP_REQUIRE_VIRTUALENV`
Posted on 05 Nov, 2021
To make sure you have an virtual env activated whenever you do pip install, add the following line to your .bashrc
1
export PIP_REQUIRE_VIRTUALENV=true
Copied!
If you now try to install packages outside a virtual environment pip will remind you.
1
$ pip install django
2
ERROR: Could not find an activated virtualenv (required).
Copied!
In some cases you will need to install global packages (like vim plugins etc). For that create a separate bash function like this
1
gpip() {
2
PIP_REQUIRE_VIRTUALENV=false pip "[email protected]"
3
}
Copied!
Copy link
Edit on GitHub