-
Notifications
You must be signed in to change notification settings - Fork 3k
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 uncaught TypeError accessing setuptools_dist.version #13071
base: main
Are you sure you want to change the base?
Conversation
This sounds like your copy of setuptools is not installed correctly, lacking the necessary installation metadata. Is it possible that the setuptools install was done by conda, and conda isn't following the standard for how to record package metadata? I appreciate that a failure in this situation is annoying, but it has demonstrated that there's a problem with the underlying installation, and I'm inclined to say that the correct thing to do is for you to fix that problem, rather than for pip to simply ignore it. |
Thanks for the quick reply.
I'm not sure what resulted in the setuptools metadata in this environment getting into this state. But as I mentioned, running Something like this ought to provide a minimal repro (untested): FROM jupyter/minimal-notebook@sha256:67fcff2665c371ffa29b78255bb0591672c5ca20487df0887f55685cd6f9b7aa
# Uncomment out to work around the bug triggered by the pip install below
# RUN conda install setuptools
# Repro
RUN /opt/conda/bin/pip install "faiss-cpu<=1.8.0"
While we don't yet know how the setuptools installation has gotten into this bad state and how many users it could be affecting, it seems to me that it would be better for pip users if pip proceeded to install the package the user needs, which is the user's goal, and at most warned about the setuptools installation, rather than hard-failing just because it couldn't include the setuptools version in the User-Agent header, which is not the user's goal. If failing to find the setuptools version will definitely cause other problems that will get in the way of the user's goal, it would be another story, but I'm not sure that's the case. We've been using this base image's base conda environment (without first reinstalling setuptools in it) to serve jupyter lab to our users for a while now with no problems. We only started to hit this recently upon conda installing jupyterlab-ai in that environment (due to its questionable practice of calling |
I can't reproduce your error, the dockerfile fails to build:
Without the hash is builds fine:
|
I forgot the "quay.io". FROM quay.io/jupyter/minimal-notebook@sha256:67fcff2665c371ffa29b78255bb0591672c5ca20487df0887f55685cd6f9b7aa
# ... ❯ docker build . # succeeds
...
=> [internal] load metadata for quay.io/jupyter/minimal-notebook@sha256:67fcff2665c371ffa29b78255bb0591672c5ca20487df0887f55685cd6f9b7aa 0.2s
...
=> exporting to image 0.0s |
Builds but doesn't reproduce the error:
The problem seems deeper than "I can't generate a part of a user agent string". The version of an allegedly installed distribution is throwing an error, lots of operations in pip require knowing the versions of installed distributions, coding defensively here seems like it would make the error pop up later down the line. |
Was hoping I'd correctly eyeballed a minimal repro, but alas. And I can't share the unminimized code where this reproduces since it's proprietary. I'm afraid I won't be able to take this farther any time soon. Feel free to close if you disagree with the patch and thanks for your consideration. |
The latest version of pip is missing some defensive code when trying to populate the User-Agent header and the setuptools_dist.version is not as expected, leading to errors like the following:
This looks similar to #11352.
One example of where this occurs is when attempting to
pip install
a package in the "base" conda environment in the docker images provided by https://github.com/jupyter/docker-stacks. This occurs both with the latest release version of pip installed in the environment, as well as the latest development version. While this issue is unaddressed, I am working around it by reinstalling setuptools in this environment, which allows subsequent pip install invocations to succeed.This patch addresses the issue by catching the TypeError and skipping the population of the setuptools_version in this case. Better to allow installation to continue with a User-Agent header that is missing the setuptools version than to hard fail just because of some missing telemetry.
In that spirit, perhaps there should be a broader
try/except Exception
around the entireself.headers["User-Agent"] = user_agent()
call, but I'm starting with the most minimal patch that would address the issue.If any changes are required to this patch before it will be merged, I will do my best, but unfortunately can't promise anything more than this initial submission. I hope this is helpful in any case.