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

Modify install paths for prior Debian system Pythons #2113

Closed
charliermarsh opened this issue Mar 1, 2024 · 4 comments
Closed

Modify install paths for prior Debian system Pythons #2113

charliermarsh opened this issue Mar 1, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@charliermarsh
Copy link
Member

Within:

# Use bullseye
FROM debian:bullseye

RUN apt-get update
RUN apt-get install python3 python3-pip python3-venv -y

We see:

root@ff9ce2004eb7:/# python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_paths()
{'stdlib': '/usr/lib/python3.9', 'platstdlib': '/usr/lib/python3.9', 'purelib': '/usr/lib/python3.9/site-packages', 'platlib': '/usr/lib/python3.9/site-packages', 'include': '/usr/include/python3.9', 'platinclude': '/usr/include/python3.9', 'scripts': '/usr/bin', 'data': '/usr'}
>>> import sys
>>> sys.path
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/dist-packages', '/usr/lib/python3/dist-packages']

So when installing into Debian's system Python, we'll end up installing into the "wrong" place. See Filipe's excellent article on it here: https://ffy00.github.io/blog/02-python-debian-and-the-install-locations/.

(I don't see this issue with latest Debian.)

@charliermarsh charliermarsh added the bug Something isn't working label Mar 1, 2024
@charliermarsh charliermarsh self-assigned this Mar 1, 2024
@charliermarsh
Copy link
Member Author

This is really complex, we'd need to vendor quite a lot of Python code from pip. It also seems like disutils needs a distribution name in order to generate paths, but we want to generate these without such a name. Maybe it's possible? Will play around with it.

@charliermarsh
Copy link
Member Author

Note that this only affects installing with --system.

@charliermarsh
Copy link
Member Author

It also seems like disutils needs a distribution name in order to generate paths, but we want to generate these without such a name. Maybe it's possible? Will play around with it.

Yes, possible, virtualenv does it without providing a dist name.

@charliermarsh
Copy link
Member Author

charliermarsh commented Mar 2, 2024

The thing we want to do here is:

Add all of this to get_interpreter_info.py, and change our internal structs to use the Scheme schema rather than SysconfigPaths (i.e., a subset). However, instead of headers, we should use include, and omit the distribution name from the end, so that it's generic across distributions. (It should (?) be okay to omit the distribution name when calling distutils, virtualenv omits it, although I'm not 100% sure.)

You can also see an example of how virtualenv does this: https://github.com/pypa/virtualenv/blob/5cd543fdf8047600ff2737babec4a635ad74d169/src/virtualenv/discovery/py_info.py#L80.

charliermarsh added a commit that referenced this issue Mar 2, 2024
## Summary

Covering some of the limitations from
#2113.
charliermarsh added a commit that referenced this issue Mar 5, 2024
## Summary

`pip` uses `sysconfig` for Python 3.10 and later by default; however, it
falls back to `distutils` for earlier Python versions, and distros can
actually tell `pip` to continue falling back to `distutils` via the
`_PIP_USE_SYSCONFIG` variable.

By _always_ using `sysconfig`, we're doing the wrong then when
installing into some system Pythons, e.g., on Debian prior to Python
3.10.

This PR modifies our logic to mirror `pip` exactly, which is what's been
recommended to me as the right thing to do.

Closes #2113.

## Test Plan

Most notably, the new Debian tests pass here (which fail on main:
#2144).

I also added Pyston as a second stress-test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant