Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (0 / 6) |
Uptime: | 00:58:30 |
Calls: | 425 |
Files: | 1,025 |
Messages: | 91,686 |
I am using *Python 3.13* in a virtual environment under *Ubuntu Linux 24.04* .
The version of Python was compiled from source code and installed with make altinstall. I attempted to use *pip* to install the *Sphinx* package into
the virtual environment using the command *pip install sphinx* in the
virtual environment*.* I expected that *sphinx* would be installed in the *site-packages* directory in the virtual environment. Instead, it was installed into the site-packages directory in */home/jonathan/.locals/lib/python3.13/site-packages* even though I did not specify *--user* to the *pip install* command. Is this expected behavior? I wanted Sphinx to be installed in the virtual environment so that it would
be accessible to all users of the virtual environment.
The version of Python was compiled from source code and installed with
make altinstall. I attempted to use *pip* to install the *Sphinx*
package into the virtual environment using the command *pip install
sphinx* in the virtual environment*.
The virtual environment was owned by the user running pip. It was not
owned by root. Does pip not support virtual environments that are owned
by a non-root user and have a multi-user secondary group? The actual
command was *pip install mypy flake8 sphinx*. The other packages were
also installed into the user .local tree and work properly for the user
doing the installation, but not for other members of the group that have access to the virtual environment.
On Sun, Apr 13, 2025 at 10:11 PM Thomas Passin <list1@tompassin.net <mailto:list1@tompassin.net>> wrote:
On 4/13/2025 7:10 PM, Jonathan Gossage via Python-list wrote:
> I am using *Python 3.13* in a virtual environment under *Ubuntu
Linux 24.04*
> .
> The version of Python was compiled from source code and installed
with make
> altinstall. I attempted to use *pip* to install the *Sphinx*
package into
> the virtual environment using the command *pip install sphinx* in the
> virtual environment*.* I expected that *sphinx* would be
installed in the
> *site-packages* directory in the virtual environment. Instead, it was
> installed into the site-packages directory in
> */home/jonathan/.locals/lib/python3.13/site-packages* even though
I did not
> specify *--user* to the *pip install* command. Is this expected
behavior? I
> wanted Sphinx to be installed in the virtual environment so that
it would
> be accessible to all users of the virtual environment.
If you ran the command as a user, then pip would not have root
privileges and could not install into the system directory. It would
fall back to installing into the user's tree. It usually prints a
message to that effect. That's standard behavior if you don't have the
venv activated.
If you want to install something into a virtual environment, you
have to
activate the environment before installing the something.
A complication could occur if the system's Python version is the
same as
the one you built. You might inadvertently run the system's binary of
python 3.13 instead of your own. I'm not familiar with the make
altinstall command but I doubt that it changes the ordinary rules for
invoking python and using a venv.
--
Jonathan Gossage
Pip doesn't know about the environment it runs in. It seems to me that
you didn't active the venv before you installed using pip. So nothing
would have gotten installed into the venv. So where is the venv that you
set up? I usually put them into ~/venv. For example, a venv named "gf4"
is at ~/venv/gf4.
Making the active script executable introdues the risk that you'll accidentally execute it rather than sourcing it. If you do that, it
will probably set up the environment in a new shell process which then immediately terminates.
Thomas Passin <list1@tompassin.net> writes:
[...]
To activate a venv, you have to source its activate script, which is[...]
in the venv. First you have to mark it as executable. Then you source
it -
source ~/venv/gf4/bin/activate
No, you don't have to (and probably shouldn't) mark the script as
executable.
Making a script executable (chmod +x) is required before *executing* it,
but when you *source* a script (using "source" or "."), your current
shell reads it and evaluates its content.
Making the active script executable introdues the risk that you'll accidentally execute it rather than sourcing it. If you do that, it
will probably set up the environment in a new shell process which then immediately terminates.
Thomas Passin <list1@tompassin.net> writes:
[...]
To activate a venv, you have to source its activate script, which is[...]
in the venv. First you have to mark it as executable. Then you source
it -
source ~/venv/gf4/bin/activate
No, you don't have to (and probably shouldn't) mark the script as
executable.
Making a script executable (chmod +x) is required before *executing* it,
but when you *source* a script (using "source" or "."), your current
shell reads it and evaluates its content.
Making the active script executable introdues the risk that you'll accidentally execute it rather than sourcing it. If you do that, it
will probably set up the environment in a new shell process which then immediately terminates.
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.
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*
On 14/04/25 11:10, Jonathan Gossage via Python-list wrote:
I am using *Python 3.13* in a virtual environment under *Ubuntu Linux
24.04*
.
The version of Python was compiled from source code and installed with
make
altinstall. I attempted to use *pip* to install the *Sphinx* package into
the virtual environment using the command *pip install sphinx* in the
virtual environment*.* I expected that *sphinx* would be installed in the
*site-packages* directory in the virtual environment. Instead, it was
installed into the site-packages directory in
*/home/jonathan/.locals/lib/python3.13/site-packages* even though I
did not
specify *--user* to the *pip install* command. Is this expected
behavior? I
wanted Sphinx to be installed in the virtual environment so that it would
be accessible to all users of the virtual environment.
Which command did you type?
Which type of virtual-environment, and was it activated at the time?
Various responses have been provided but the OP has not yet replied on-
list (as verified by Archive). Is this an error with the list-processor
or have some posts been sent to one person only (using Reply instead of ReplyList)?
There are always others who would like to learn from list-discussions -
but will hearing only half of some of the conversation help them?
On 14/04/25 11:33, dn via Python-list wrote:
On 14/04/25 11:10, Jonathan Gossage via Python-list wrote:
I am using *Python 3.13* in a virtual environment under *Ubuntu Linux
24.04*
.
The version of Python was compiled from source code and installed
with make
altinstall. I attempted to use *pip* to install the *Sphinx* package
into
the virtual environment using the command *pip install sphinx* in the
virtual environment*.* I expected that *sphinx* would be installed in
the
*site-packages* directory in the virtual environment. Instead, it was
installed into the site-packages directory in
*/home/jonathan/.locals/lib/python3.13/site-packages* even though I
did not
specify *--user* to the *pip install* command. Is this expected
behavior? I
wanted Sphinx to be installed in the virtual environment so that it
would
be accessible to all users of the virtual environment.
Which command did you type?
Which type of virtual-environment, and was it activated at the time?
Am Mo., 14. Apr. 2025 um 01:14 Uhr schrieb Jonathan Gossage via Python-list <python-list@python.org>:
I am using *Python 3.13* in a virtual environment under *Ubuntu Linux
24.04*
.
[...]
Instead, it was
installed into the site-packages directory in
*/home/jonathan/.locals/lib/python3.13/site-packages* even though I did not >> specify *--user* to the *pip install* command. Is this expected behavior? I >> wanted Sphinx to be installed in the virtual environment so that it would
be accessible to all users of the virtual environment.
Hi Jonathan,
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.
Do you have, by any chance, one of the following pip-related configuration files present?
- /etc/pip.conf
- ~/.config/pip/pip.conf
- ~/.pip/pip.conf (lagacy)
I took this list from https://pip.pypa.io/en/stable/topics/configuration/. *If* there is any such file present, you might look out for a line:
user = true
but I am not entirely certain about this.
Looking forward to your reply!
Best,
Friedrich
On Linux, at least, it's standard for pip to install into the user's site-packages location if it's not invoked with admin privileges - even without --user. Pip will emit a message saying so. Well, that used to be
true but nowadays Pip wants you to use the --break-system-packages flag
if you want to insist on installing into the system's Python install,
even if it's going to go into --user. I'm not sure if the restriction
will be in place given that the OP built his own Python version.
On 2025-04-15, Thomas Passin via Python-list <python-list@python.org> wrote:
On Linux, at least, it's standard for pip to install into the user's
site-packages location if it's not invoked with admin privileges - even
without --user. Pip will emit a message saying so. Well, that used to be
true but nowadays Pip wants you to use the --break-system-packages flag
if you want to insist on installing into the system's Python install,
even if it's going to go into --user.
I've always been a little baffled by that message when installing with --user. How can that possibly break system stuff?
On Tue, 15 Apr 2025 14:12:19 -0400, Thomas Passin wrote:
On Linux, at least, it's standard for pip to install into the user's
site-packages location if it's not invoked with admin privileges - even
without --user. Pip will emit a message saying so. Well, that used to be
true but nowadays Pip wants you to use the --break-system-packages flag
if you want to insist on installing into the system's Python install,
even if it's going to go into --user. I'm not sure if the restriction
will be in place given that the OP built his own Python version.
Is that pip or a distro's version of pip? On Fedora I get the message
about defaulting to user. On Ubuntu I get a message to use a venv or if I really want a global install to use something like 'pip install python3- black'. Ubuntu's is pip 24.2, Fedor's is 24.3.1 but neither of them show '--break-system-packages' in --help.
To be clear: you do not have to activate a virtualenv to use *Python*And the pip command that is found and run will use it's own settings
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.
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.
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 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.
On 2025-04-17, Left Right via Python-list <python-list@python.org> wrote:Sure, and it's "your fault" (sic) if you break yourself. You and I can
Also... when installing stuff with pip --user, it is always a package
that is not installed for the system (usually not even available for
the system). How can that "break system packages"?
pip installs dependencies. Dependencies may disagree on the version
with the system packages.
Good point. I don't generally allow pip to install dependencies, so I
forgot about that source of conflict. But as far as I can see, it
still can only break stuff for the user, not for the system. The
system is never going to look in my ~/.local/lib/python* directories.
There's just not a really great answer to this.
On 18/04/25 9:41 am, Mats Wichmann wrote:
There's just not a really great answer to this.
Seems to me a system-installed application shouldn't be looking in the
user's .local packages in the first place. That should only be for things
the user has installed "for this user".
On 2025-04-18 13:24:28 +1200, Greg Ewing via Python-list wrote:
On 18/04/25 9:41 am, Mats Wichmann wrote:
There's just not a really great answer to this.
Seems to me a system-installed application shouldn't be looking in the
user's .local packages in the first place. That should only be for things
the user has installed "for this user".
It's not the application that looks into .local, it's Python. If you say
that a system-installed Python shouldn't look into ~/.local, then you've
just disabled that mechanism completely. If not then Python would
somehow have to distinguish between system-installed and user-installed scripts. This isn't as easy as checking whether the path starts with
/usr/bin or whether it belongs to root. Tying into the system's package manager doesn't look appealing to me (not to mention that it might be unacceptably slow).
On Fri, 18 Apr 2025 at 16:50, Peter J. Holzer via Python-list <python-list@python.org> wrote:
On 2025-04-18 13:24:28 +1200, Greg Ewing via Python-list wrote:
On 18/04/25 9:41 am, Mats Wichmann wrote:
There's just not a really great answer to this.
Seems to me a system-installed application shouldn't be looking in the user's .local packages in the first place. That should only be for things the user has installed "for this user".
It's not the application that looks into .local, it's Python. If you say that a system-installed Python shouldn't look into ~/.local, then you've just disabled that mechanism completely. If not then Python would
somehow have to distinguish between system-installed and user-installed scripts. This isn't as easy as checking whether the path starts with /usr/bin or whether it belongs to root. Tying into the system's package manager doesn't look appealing to me (not to mention that it might be unacceptably slow).
Couldn't the system-installed scripts have a shebang like:
#!/usr/bin/python3 -s
On 4/18/2025 11:38 AM, Peter J. Holzer via Python-list wrote:
On 2025-04-18 13:24:28 +1200, Greg Ewing via Python-list wrote:
On 18/04/25 9:41 am, Mats Wichmann wrote:
There's just not a really great answer to this.
Seems to me a system-installed application shouldn't be looking in the user's .local packages in the first place. That should only be for things the user has installed "for this user".
It's not the application that looks into .local, it's Python. If you say that a system-installed Python shouldn't look into ~/.local, then you've just disabled that mechanism completely. If not then Python would
somehow have to distinguish between system-installed and user-installed scripts. This isn't as easy as checking whether the path starts with /usr/bin or whether it belongs to root. Tying into the system's package manager doesn't look appealing to me (not to mention that it might be unacceptably slow).
Let's try a specific example. Let's say that PyQt6 v6.8.3 is installed in
the system site directory. The OS uses PyQt6 for some system purposes. Now the user comes along and forces an install of PyQt6 v6.9.0 in the user site directory. 6.9.0 has a bug that would crash one of the system's application but not the user's programs. (This is not a far-fetched scenario).
When the system launches its application the PYTHONPATH will start with system site directories; local user site directories will be on the PYTHONPATH but since they come later, the python will use PyQt6 v6.8.3 because that will come first on the path. No crash here.
If the user has a program that actually does require the use of v6.9.0, he's going to have to make sure that the user's local site directories come first on the path. One way to do that is to set the PYTHONPATH to point to the user's location.
In what scenario is a system application going to load a wrong version of a dependency from a user's site location?
The only one I can think of is for the user, with the help of sudo, or
by editing some system-enabled script, were to change the global
PYTHONPATH. That seems a stretch.
On 2025-04-18 13:08:36 -0400, Thomas Passin via Python-list wrote:...
When the system launches its application the PYTHONPATH will start with
system site directories; local user site directories will be on the
PYTHONPATH but since they come later, the python will use PyQt6 v6.8.3
because that will come first on the path. No crash here.
If the user has a program that actually does require the use of v6.9.0, he's >> going to have to make sure that the user's local site directories come first >> on the path. One way to do that is to set the PYTHONPATH to point to the
user's location.
This is IMHO not practical. The user would have to set PYTHONPATH for
some programs, but not for others. You can't do this with .bashrc (or similar), the user would have to write a wrapper script for each of
their programs which depend on something in ~/.local. Possible of course
but cumbersome.
I like Oscar's suggestion that Python scripts provided by the
distribution include -s in the shebang much better.
Or - what I tend to do - simply use a virtual environment for each
script that needs a package that the system doesn't provide. But of
course that's basically "disable/don't use .local" and all those venvs
take space and need to be maintained.
The only one I can think of is for the user, with the help of sudo, or
by editing some system-enabled script, were to change the global
PYTHONPATH. That seems a stretch.
No, there doesn't have to be a global (in the sense that it applies to
all users) PYTHONPATH for that to happen. You just need a PYTHONPATH
that is set for all processes of that user - which the user can
certainly set without sudo (usually by editing .bashrc or maybe using
their desktop environment's settings dialog).
On 2025-04-18 13:08:36 -0400, Thomas Passin via Python-list wrote:
On 4/18/2025 11:38 AM, Peter J. Holzer via Python-list wrote:
On 2025-04-18 13:24:28 +1200, Greg Ewing via Python-list wrote:
On 18/04/25 9:41 am, Mats Wichmann wrote:
There's just not a really great answer to this.
Seems to me a system-installed application shouldn't be looking in the >>>> user's .local packages in the first place. That should only be for things >>>> the user has installed "for this user".
It's not the application that looks into .local, it's Python. If you say >>> that a system-installed Python shouldn't look into ~/.local, then you've >>> just disabled that mechanism completely. If not then Python would
somehow have to distinguish between system-installed and user-installed
scripts. This isn't as easy as checking whether the path starts with
/usr/bin or whether it belongs to root. Tying into the system's package
manager doesn't look appealing to me (not to mention that it might be
unacceptably slow).
Let's try a specific example. Let's say that PyQt6 v6.8.3 is installed in
the system site directory. The OS uses PyQt6 for some system purposes. Now >> the user comes along and forces an install of PyQt6 v6.9.0 in the user site >> directory. 6.9.0 has a bug that would crash one of the system's application >> but not the user's programs. (This is not a far-fetched scenario).
Agreed. Also since PyQt6 is a GUI framework, I'm going to assume that
those applications are supposed to be invoked by the user on their
desktop, not by a cronjob controlled by the system.
When the system launches its application the PYTHONPATH will start with
system site directories; local user site directories will be on the
PYTHONPATH but since they come later, the python will use PyQt6 v6.8.3
because that will come first on the path. No crash here.
If the user has a program that actually does require the use of v6.9.0, he's >> going to have to make sure that the user's local site directories come first >> on the path. One way to do that is to set the PYTHONPATH to point to the
user's location.
This is IMHO not practical. The user would have to set PYTHONPATH for
some programs, but not for others. You can't do this with .bashrc (or similar), the user would have to write a wrapper script for each of
their programs which depend on something in ~/.local. Possible of course
but cumbersome.
I like Oscar's suggestion that Python scripts provided by the
distribution include -s in the shebang much better.
Or - what I tend to do - simply use a virtual environment for each
script that needs a package that the system doesn't provide. But of
course that's basically "disable/don't use .local" and all those venvs
take space and need to be maintained.
In what scenario is a system application going to load a wrong version of a >> dependency from a user's site location?
When the user sets PYTHONPATH and then accidentally invokes the system-supplied application without resetting it first.
The only one I can think of is for the user, with the help of sudo, or
by editing some system-enabled script, were to change the global
PYTHONPATH. That seems a stretch.
No, there doesn't have to be a global (in the sense that it applies to
all users) PYTHONPATH for that to happen. You just need a PYTHONPATH
that is set for all processes of that user - which the user can
certainly set without sudo (usually by editing .bashrc or maybe using
their desktop environment's settings dialog).
My problem with venvs, especially if I have more than one, is that I eventually forget what they were for and what is different about each
one. If there's only one and it's used for all non-system work, that's
OK but beyond that and they tend to suffer knowledge rot.