guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guix's python has pip's user dir in its loadpath


From: Wojtek Kosior
Subject: Re: Guix's python has pip's user dir in its loadpath
Date: Sat, 1 Jul 2023 13:32:57 +0200

The precedence of local, pip-installed Python libraries over Guix ones
has already been a source of bugs. And these can be hard to diagnose.

I imagine an optimal solution would be to configure this behavior on
per-package basis. The vast majority of applications does not need to
load local libraries. There are just a few exceptions like
`python-virtualenv`.

Once I did write a package definition that deliberately disabled user
site dir package loading. I used code similar to what's below.

> (modify-phases %standard-phases
>   (add-after 'wrap 'prevent-local-package-interference
>     (lambda* (#:key outputs #:allow-other-keys)
>       (substitute* (string-append (assoc-ref outputs "out")
>                                   "/bin/<program-name>")
>         (("^#!/.*$" shabang)
>          (string-append shabang
>                         "export PYTHONNOUSERSITE=1\n"))))))

Of course, it makes no sense to add such snippet to all definitions.
Instead, we could modify python-build-system to allow doing a similar
thing based on a flag passed in package's `(arguments)`.

Wojtek

-- (sig_start)
website: https://koszko.org/koszko.html
fingerprint: E972 7060 E3C5 637C 8A4F  4B42 4BC5 221C 5A79 FD1A
follow me on Fediverse: https://friendica.me/profile/koszko/profile

♥ R29kIGlzIHRoZXJlIGFuZCBsb3ZlcyBtZQ== | ÷ c2luIHNlcGFyYXRlZCBtZSBmcm9tIEhpbQ==
✝ YnV0IEplc3VzIGRpZWQgdG8gc2F2ZSBtZQ== | ? U2hhbGwgSSBiZWNvbWUgSGlzIGZyaWVuZD8=
-- (sig_end)


On Fri, 30 Jun 2023 23:13:55 -0400 Maxim Cournoyer <maxim.cournoyer@gmail.com> 
wrote:

> Hi,
> 
> 宋文武 <iyzsong@envs.net> writes:
> 
> > edk@beaver-labs.com writes:
> >  
> >> Dear Guix devs,
> >>
> >> While working around this bug:
> >>
> >> https://issues.guix.gnu.org/63912
> >>
> >> I found that guix's Python will load anything in
> >> .local/lib/python3.10/site-packages/ over any installed package in the
> >> current profile. This makes pip-installed package overshadow guix's.
> >>
> >> I'm not sure this is desirable behavior. What I was expecting was for
> >> the host system's python packages to be completely ignored.  
> >
> > Hello, I think this is a well-known issue according to PEP 668:
> > https://peps.python.org/pep-0668/  
> 
> Agreed, I think this works as designed: the Guix-installed dependencies
> appear as *system* dependencies on the sys.path (see 'python -m site'),
> and USER_SITE (which is ~/.local/lib/python3.10/site-packages) must have
> precedence over it for locally user-installed packages to be able to
> override the system packages.
> 
> That's for example necessary for virtualenvs to work as designed (it
> used to be that virtualenvs were near useless, with the Guix-provided
> dependencies taking precedence on the ones installed in a virtualenv).
> 

Attachment: pgphc8OhOuiIL.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]