Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the install scheme to posix_prefix when --prefix is passed #10978

Open
1 task done
frostming opened this issue Mar 22, 2022 · 12 comments
Open
1 task done

Fix the install scheme to posix_prefix when --prefix is passed #10978

frostming opened this issue Mar 22, 2022 · 12 comments
Labels
project: <downstream> When the cause/effect is related to redistributors type: bug A confirmed bug or unintended behavior

Comments

@frostming
Copy link
Contributor

frostming commented Mar 22, 2022

What's the problem this feature will solve?

On Debian systems, due to the sysconfig patch, sysconfig.get_preferred_scheme('prefix') will return posix_local, which is also the default scheme. This causes problem when using --prefix <path> with pip install, where packages are installed to <prefix_path>/local/lib/pythonX.Y/dist-packages. This is apparently wrong.

Describe the solution you'd like

Add a special case to pip._internal.locations._sysconfig:get_scheme(), when posix_local is found in INSTALL_SCHEMES and prefix is not None, rewrite the scheme as posix_prefix.

Alternative Solutions

I am not sure if it is better to report it to Debian, but IMO it makes more sense to fix it in pip to be more robust.

Additional context

Code of Conduct

@frostming frostming added S: needs triage Issues/PRs that need to be triaged type: feature request Request for a new feature labels Mar 22, 2022
@uranusjr
Copy link
Member

What is the behaviour of the distutils backend?

@pradyunsg
Copy link
Member

I am not sure if it is better to report it to Debian, but IMO it makes more sense to fix it in pip to be more robust.

If this behaviour originates due to a Debian patch, it is usually a good idea to file an issue with them. Please file a bug with Debian, with reportbug python3-pip (their reporting documentation). You can link to this issue in your bug report.

@pradyunsg pradyunsg added type: bug A confirmed bug or unintended behavior project: <downstream> When the cause/effect is related to redistributors and removed type: feature request Request for a new feature S: needs triage Issues/PRs that need to be triaged labels Mar 22, 2022
@frostming
Copy link
Contributor Author

What is the behaviour of the distutils backend?

They are different:

>>> from pip._internal.locations import _distutils, _sysconfig
>>> _sysconfig.get_scheme('click', prefix='myprefix').purelib
'myprefix/local/lib/python3.10/dist-packages'
>>> _distutils.get_scheme('click', prefix='myprefix').purelib
'myprefix/lib/python3.10/site-packages'

If this behaviour originates due to a Debian patch, it is usually a good idea to file an issue with them. Please file a bug with Debian, with reportbug python3-pip (their reporting documentation). You can link to this issue in your bug report.

Thanks for the guidance but I am not able to do so now(some problem with reportbug).

@uranusjr
Copy link
Member

Hmm yeah at least they should match. I don’t think Debian can handle this though; the --prefix value is not passed to sysconfig so they have no way to magically choose a scheme based on it. We’ll likely need to somehow handle this in pip, or raise an issue to CPython to further enhance the sysconfig API.

@speth
Copy link

speth commented Apr 5, 2022

I'm seeing a similar problem on Fedora 37 (Rawhide) while trying to package a Python module (see Cantera/cantera#1233), using both the Fedora-packaged version of pip or pip installed from PyPI, so I don't think that this is only a Debian problem. In both cases this is using pip 22.0.4. There are some differences, though, compared to the behavior reported on Debian -- I see the local directory being incorrectly inserted through both routes:

>>> from pip._internal.locations import _distutils, _sysconfig
>>> _sysconfig.get_scheme('click', prefix='myprefix').purelib
'myprefix/local/lib/python3.10/site-packages'
>>> _distutils.get_scheme('click', prefix='myprefix').purelib
'myprefix/local/lib/python3.10/site-packages'

@uranusjr
Copy link
Member

uranusjr commented Apr 6, 2022

If it's injected for both implementations, this is not a bug but an intended behaviour. You need to check with Red Hat to understand their intention behind this and resolve the issue there, pip cannot change it here.

@henryptung
Copy link

Not to disrupt the conversation, but isn't the prefix install scheme fairly-explicitly specified in https://docs.python.org/3/install/index.html#alternate-installation-unix-the-prefix-scheme? Is this behavior changing, and is that documented somewhere?

@uranusjr
Copy link
Member

It’s not the install prefix that’s the problem, but Debian changes how it uses the install prefix, and we need their confirmation why they changed one place but not the other (and if one of them is wrong, which is the right one).

@adamjstewart
Copy link

We also ran into this same issue in Spack where we use pip to install packages to unique installation prefixes. Thanks @trws for finding this bug report.

@pradyunsg
Copy link
Member

pradyunsg commented Aug 15, 2022

FWIW, Fedora also has a similarly breaking patch (https://github.com/fedora-python/cpython/blob/f52f499bb9ac03d7793fa2e1ccaaab8a3169685e/Lib/sysconfig.py#L77) and they directly modify posix_prefix.

I suggest we move further discussion to https://discuss.python.org/t/18240, mostly because that's a better forum for the sort of cross-project discussion that this is gonna need.

stephankramer added a commit to FluidityProject/spud that referenced this issue Oct 31, 2022
To avoid having to deal with the setup.py install vagueries when installing python for Debian packaging, let pybuild take care of the building and installing of python. Rewrite debian/rules to make use of debhelper for as much as possible and minimize hackery. Also remove Debian-packaging-specific hacks in Makefile.in

The recipe we are now following is to install everything in debian/tmp (instead of straight into the debian/<package>/ directories), and divide the resulting files up over the packages using debian/<package.install> files. Try to clean up some Lintin errors and warnings in the process.

Note that we are still using distutils in the setup.py files and calling
"python setup.py install" which are both deprecated. Only this
combination appears to not be hit by pypa/pip#10978
so just leaving as is.

Also introduces:
* testing on both Focal and Jammy
* fix intermittent test failure in build process
@simonvanderveldt
Copy link

simonvanderveldt commented Dec 7, 2022

This causes problem when using --prefix <path> with pip install, where packages are installed to <prefix_path>/local/lib/pythonX.Y/dist-packages. This is apparently wrong.

Not sure if I'm misunderstanding the issue description but for me it seems to have a different/the opposite behavior with regards to site/dist-packages.

Installing a Python package using pip3 in Debian without --prefix installs the package in /usr/local/lib/python3.7/dist-packages (so in dist-packages in local) whereas when using --prefix it gets installed in <prefix>/lib/python3.7/site-packages (so in site-packages not in local). So for some reason they are not installed to dist-packages when using --prefix.
This is causing some issues for me. I'm not sure what the intended behavior is?

This was tested on Debian Buster as well as Debian Bullseye which has

root@b95b3bc69071:/# pip --version
pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)

bjoernricks added a commit to greenbone/docs that referenced this issue Dec 12, 2022
Using the `--prefix` argument is broken with newer pip versions and at
least Python 3.10. The distros are patching CPython's sysconfig module
which breaks our `--prefix` argument expected behavior. Because the
default is install prefix is already `/usr/local` we just can remove the
`--prefix` argument to circumvent the bug.

See the following links for details:

* pypa/pip#11651
* pypa/pip#10978
* https://discuss.python.org/t/linux-distro-patches-to-sysconfig-are-changing-pip-install-prefix-outside-virtual-environments/18240
bjoernricks added a commit to greenbone/docs that referenced this issue Dec 12, 2022
Using the `--prefix` argument is broken with newer pip versions and at
least Python 3.10. The distros are patching CPython's sysconfig module
which breaks our expected behavior if the `--prefix` argument . Because
the default install prefix is already `/usr/local` we just can remove
the `--prefix` argument to circumvent the bug.

See the following links for details:

* pypa/pip#11651
* pypa/pip#10978
* https://discuss.python.org/t/linux-distro-patches-to-sysconfig-are-changing-pip-install-prefix-outside-virtual-environments/18240
bjoernricks added a commit to greenbone/docs that referenced this issue Dec 12, 2022
Using the `--prefix` argument is broken with newer pip versions and at
least Python 3.10. The distros are patching CPython's sysconfig module
which breaks our expected behavior if the `--prefix` argument . Because
the default install prefix is already `/usr/local` we just can remove
the `--prefix` argument to circumvent the bug.

See the following links for details:

* pypa/pip#11651
* pypa/pip#10978
* https://discuss.python.org/t/linux-distro-patches-to-sysconfig-are-changing-pip-install-prefix-outside-virtual-environments/18240
@martinpitt
Copy link

The corresponding Debian bug report is https://bugs.debian.org/1035546 . Perhaps you can edit the description to make it easier to find? Thanks!

m-elwin added a commit to omnid/cmakeme that referenced this issue Dec 15, 2023
1. Need to work around pypa/pip#10978
   - This issue was preventing the use pip install to install the wheel
     because there was no way to remove local/ from the prefix
     but the problem seems to only be on debian-based systems so
     working around it would be difficult

2. The solution is that now cmakeme extracts the wheel manually and installs
   it to the proper location.
   Advantages to this approach:
     1. There is no dependency on pip being installed. Instead the whl is just
        a zip archive which can be extracted with a cmake -E command
     2. Hacks related to finding the full wheel name are no longer needed because
        the wheel is extracted at build time instead of compile time
     3. Installation is cleaner (from a cmake code perspective) because it is just copying the extracted wheel
        to the proper directory.
   Disadvantage
    1. Essentially, this is cmake simulating a wheel install by unzipping.
       pip might be doing some other steps, and I'm not sure what they are
       and there might be packages where the approach here does not deal
       with all cases, and I might not even be always putting things in the correct directory
    2. However, the main goal is for it to be in a directory that ROS code can find things.
NexediGitlab pushed a commit to Nexedi/re6stnet that referenced this issue Oct 21, 2024
Calling `make install` fails when specifying /usr as prefix,
because of pypa/pip#10978.
NexediGitlab pushed a commit to Nexedi/re6stnet that referenced this issue Oct 21, 2024
Because of pypa/pip#10978,
`make install` is currently unable to install the Python code
to a custom prefix (PREFIX).
NexediGitlab pushed a commit to Nexedi/re6stnet that referenced this issue Oct 21, 2024
Because of pypa/pip#10978,
`make install` is currently unable to install the Python code
to a custom prefix (PREFIX).
NexediGitlab pushed a commit to Nexedi/re6stnet that referenced this issue Oct 21, 2024
Because of pypa/pip#10978,
`make install` is currently unable to install the Python code
to a custom prefix (PREFIX).
NexediGitlab pushed a commit to Nexedi/re6stnet that referenced this issue Nov 2, 2024
Because of pypa/pip#10978,
`make install` is currently unable to install the Python code
to a custom prefix (PREFIX).
NexediGitlab pushed a commit to Nexedi/re6stnet that referenced this issue Nov 2, 2024
Because of pypa/pip#10978,
`make install` is currently unable to install the Python code
to a custom prefix (PREFIX).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: <downstream> When the cause/effect is related to redistributors type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

8 participants