Pip installs to unexpected place

Mats Wichmann mats at wichmann.us
Tue Apr 15 14:31:34 EDT 2025


On 4/15/25 10:43, Friedrich Romstedt via Python-list wrote:

> Many people put emphasis on that you need to *activate* a virtualenv before
> using it, but no-one so far stressed the fact that you got Sphinx installed
> to ~/jonathan/.local/lib/python3.13/site-packages *without using *--user.
To be clear: you do not have to activate a virtualenv to use *Python* 
from it. If you just call the python by the path it's in, it figures 
everything out (and sets some variables you can query vi sysconfig if 
you have reason to actually need those details (look for installation 
schemes).

What activating gives you is some path fiddling, and some prompt 
fiddling (although the prompt fiddling keeps saying it's deprecated). 
The latter is a visual clue; the former means you can also find *other* 
commands installed in the virtualenv - including pip.

/path/to/virtualenv//bin/python -m pip install ...   will work whether 
you activated or not.

pip install ...  finds the first command in your PATH named pip, which 
may or may not be the one in the virtualenv, *unless* you've activated 
it, because that's the only way the virtualenv bin directory ends up 
early in your path.

Meanwhile - the install to ~/.local : some distros just default to that 
behavior whether you ask for it or not, because they consider it unsafe 
to install in the system location. Some have chosen to yell at you even 
if you try a "user install" with the system Python. Up to them what they 
do...




More information about the Python-list mailing list