Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #197410

Re: Pip installs to unexpected place

From Thomas Passin <list1@tompassin.net>
Newsgroups comp.lang.python
Subject Re: Pip installs to unexpected place
Date 2025-04-17 08:24 -0400
Message-ID <mailman.16.1744892689.3008.python-list@python.org> (permalink)
References <CAApdmf2J69WgkR159sBSkxN0=mYoNmHZYboBmpPi+LdA-YBNpg@mail.gmail.com> <CAN06=CxPNLHtr_sdgphR2jrN1V+WbB8wZDJdbvfEDb-MYtmPHA@mail.gmail.com> <818a0fcd-72c8-4fbb-8ee4-4553f4f88f75@wichmann.us> <d9dd903b-856c-470d-b7ce-1f4ad8b49adc@roelschroeven.net> <92fc130a-7d71-4a38-aab6-881e2610fdb7@tompassin.net>

Show all headers | View raw


On 4/17/2025 4:58 AM, Roel Schroeven via Python-list wrote:
> Op 15/04/2025 om 20:31 schreef Mats Wichmann via Python-list:
>> 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.

Or you can cd to the venv directory and it will be first on the pythonpath.

> And the pip command that is found and run will use it's own settings 
> regarding where to install packages, even if you activated a virtualenv. 
> For example, you can't use /usr/bin/pip to install something in a 
> virtualenv.

pip detects if you are running in a venv and changes its behavior to match.

To install something in a virtualenv, you need to use the
> pip in that virtualenv (either by first activating that venv, or by 
> running something like venv/bin/pip, or venv). (Of course to do that pip 
> needs to be installed in that venv. That might or might not be the case 
> depending on how the venv was created.)
> 
> I kinda get the feeling that something like that is going on here.
> 

IMHO pip should always be run as a module, e.g., python3 -m pip. This 
way you always get the same pip and environment as the python executable 
that is being used.

Back to comp.lang.python | Previous | Next | Find similar


Thread

Re: Pip installs to unexpected place Thomas Passin <list1@tompassin.net> - 2025-04-17 08:24 -0400

csiph-web