-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
AssertionError no _distutils when running get-pip with Setuptools and USE_DISTUTILS=local #2993
Comments
Setuptools 60 intentionally introduced its local copy of distutils as default. As an escape hatch, you should be able to set the environment variable SETUPTOOLS_USE_DISTUTILS=stdlib while running get-pip to bypass that behavior. I know the distutils hack has an exclusion for when running under pip. That was, however, to account for pip's use of distutils. In this case, get-pip is specifically importing setuptools. Importing setuptools causes the more aggressive form of requiring distutils, where if the local copy of distutils isn't found, it fails with the reported error. So the question is - what is it about this environment that triggers this behavior? In particular, how is it that this code doesn't ensure that any existing distutils is unloaded, then loaded from Setuptools? Can someone create a set of docker steps that will replicate the issue? |
I was able to replicate the error with this Dockerfile: FROM ubuntu:focal
RUN apt update
RUN apt upgrade -y
RUN apt install -y python3-pip python3-distutils wget
RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python3 -m pip install -U setuptools
CMD python3 get-pip.py |
I did a bit of debugging and it seems that the
The hack makes the assumption that if pip is imported and it wasn't imported as part of a But setuptools makes the assertion that the hack must be available (if SETUPTOOLS_USE_DISTUTILS=local). The question is - what is it about get-pip that (a) imports pip and then (b) imports setuptools? |
I see it's these two lines where I no longer think this issue is specific to Debian or distutils. |
Indeed, the same issue occurs on my mac. All it takes is an invocation of get-pip on an existing install of
|
In the aforementioned commit, I've devised another exception that bypasses the issue (and solves the problem at least for me in this environment). I'm a little concerned that the approach is unsound, because it's essentially bypassing the other exception that was created for pip due to pypa/pip#8761. I suspect a better approach would be for get-pip not to "import setuptools" to determine if it's present, but merely to "find" it or check metadata for it. |
On further consideration, the conflict with the other exception may not be a real concern, because that exception was to support the pip upgrading setuptools case. Since get-pip is specifically not upgrading Setuptools, the concern may be moot. So my temptation is to apply the drafted fix while get-pip explores the reported issue. |
it looks like the release job failed https://github.com/pypa/setuptools/actions/runs/1650359780 so while the tag is available on github its not published to pypi currently |
Thanks for letting me know. I've identified and fixed the issue and a new release should be going out. |
In https://github.com/pypa/pip/issues/10775#issuecomment-1009375819, I summarize why I think the fix for this issue was inadequate:
I believe instead, the distutils hack should (a) detect get-pip, (b) detect "import setuptools", and in that case, satisfy "import setuptools" without actually importing anything and bypassing the distutils replacement. |
In the 2993-redux branch, I've re-visited the approach, and I believe this branch also addresses the issue reported in pypa/pip#3022:
|
…uild_clif.sh. PiperOrigin-RevId: 420775145
Somehow related: Since
setuptools
v60 at least on Debian runningget-pip.py
over an existingpip
+setuptools
fails, when the Debianpython3-distutils
package is installed, e.g. as dependency of the Python development headers package:This
_distutils_hack
comes fromget-pip.py
. Looks like removing any use and detanglingdistutils
frompip
in favour ofsetuptools
would solve both issues.Originally posted by @MichaIng in pypa/pip#10742 (comment)
The text was updated successfully, but these errors were encountered: