Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Gracefully handle python-build-standalone ImportError with Tk#30394

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@timhoffm
Copy link
Member

Closes#30390.

I've tested this locally. I don't think there's a reasonable way to test this in CI unless we are actually willing to do a uv install for this. Mocking the exception does not bring any benefit in detecting whether the error has changed, so would be largely futile.

@timhoffmtimhoffm added this to thev3.10.6 milestoneAug 5, 2025
isinstance(cause2,AttributeError)and
"'_tkinter' has no attribute '__file__'"instr(cause2)):

is_uv_python="/uv/python"in (os.path.realpath(sys.executable))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

jkseppan reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is that more helpful?

I think we should catch the error, not exclude python-build-standalone per-se. If they'd fix the tk issue, our versions would directly work. Onis_uv_python - I've explicitly tested for uv and tailored the error message, because I anticipate that'll by far the most route to trigger this, and I project that most uv users will not know what python-build-standalone is. So let's give them a uv-targeted error message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I didn't suggest excluding python-build-standalone, just detecting it differently.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

My point is I do not really care about python-build-standalone. The criterion is 1. does it raise the known error? And if so, is it a uv-install that I can point users to as the practical cause.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If that's the case that you only care aboutuv, then the PR/commit title should be adjusted.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Possibly my wording was not exactly precise.

The issue originates from thecurrent way python-build-standalone is implmented. - So the PR title is justified.

Then there are two aspects to handling:

  1. Detection: I want to detect the specific error and respond to that. - It's not helpful to detect python-build-standalone. They may improve to fix the error in the future. So issuing a warning/error purely on the fact that python-build-standalone is used would be presumptuous.

  2. Error message: In the simplest case, we could just have the second error message

    Failed to import tkagg backend. This is likely caused by using a Python executable based on python-build-standalone, which is not compatible with Tk. Please use another Python interpreter or select another backend.

    (or if you want to be more affirmative explicitly test for python-build-standalone and remove the "likely"). However, the by-far most common way to obtain a python-build-standalone python is viauv. But it's a technical detail ofuv and users are most likely not aware of it. So telling them, they have python-build-standalone is not helpful for fixing the issue. Therefore, I added theuv detection to tell them that uv-provided python is not compatible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I am 👍 on doing the work to detect if it is uv.

@geofft
Copy link
Contributor

FYI we're pretty close to fixing this in python-build-standalone - I think an error message is a good idea but it's probably not worth spending too much time working around this in detail (e.g., there's some code in Pillow that tries to work around this but doesn't quite handle things right, because that code path isn't tested, seeastral-sh/python-build-standalone#129 (comment)). I'll hopefully come back soon with a request to change the wording from "not supported" to "please upgrade" :)

timhoffm reacted with thumbs up emoji

@geofft
Copy link
Contributor

Today's releases of uv and python-build-standalone should fix this issue. (Please let me know if they do not!) I still think a warning is a good idea because uv is not very proactive at upgrading its managed Python installations, but it should suggest upgrading your version of uv and your Python installations.

For uv users,uv self update && uv python upgrade will probably do the trick, though feel free to generically "see the uv documentation" or something.

For python-build-standalone users who aren't getting it from uv, they will want today's release (20250808) or later.

jklymak reacted with thumbs up emoji

@zanieb
Copy link
Contributor

As Geoffrey noted, the canonical command we'll recommend to people isuv self update && uv python upgrade --reinstall

Copy link
Member

@tacaswelltacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

mod

Comment on lines 47 to 50
"Failed to import tkagg backend. This is likely caused by using a "
"Python executable based on python-build-standalone, which is not "
"compatible with Tk. "
"Please use another Python interpreter or select another backend."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This should be updated too to mention that a newer python-build-standalone version will fix this - for users of other tools (Poetry, mise, Bazel rules_python, etc.) there should be a path forward without changing the tools and workflow they're using, though it's not practical or necessary to specifically document what exactly they should do to upgrade.

(Also, if you're editing this, small nit above - I would specifically say that you're using anoutdated Python version, now that current uv-installed Python versions are compatible with Tk.)

"Failed to import tkagg backend. You are using a uv-installed python "
"executable, which is not compatible with Tk. "
"Please update your python via: "
"`uv self update && uv python upgrade --reinstall`"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this is fine, but just so you're aware,uv self update won't be available for users that have installed uv through their package manager instead of the standalone installer. A more "general" solution would be to "upgrade to the latest version of uv then useuv python upgrade --reinstall"

@tacaswell
Copy link
Member

@geofft@zanieb Can you please suggest edits with exactly the text you want?

@zanieb
Copy link
Contributor

zanieb commentedAug 22, 2025
edited
Loading

I'm fine with the current text. I just wanted you to be aware it's not universal so you can make an informed decision.

Here's a suggestion:https://github.com/matplotlib/matplotlib/pull/30394/files#r2294267220

Co-authored-by: Zanie Blue <contact@zanie.dev>
@timhoffm
Copy link
MemberAuthor

I believe the wording is now appropriate.

@ksundenksunden merged commitd3491dc intomatplotlib:mainAug 28, 2025
37 of 40 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestAug 28, 2025
QuLogic pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestAug 28, 2025
@timhoffmtimhoffm deleted the python-build-standalone-importerror branchAugust 29, 2025 01:38
ksunden added a commit that referenced this pull requestAug 29, 2025
…394-on-v3.10.xBackport PR#30394 on branch v3.10.x (ENH: Gracefully handle python-build-standalone ImportError with Tk)
@ksundenksunden mentioned this pull requestAug 30, 2025
5 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@QuLogicQuLogicQuLogic left review comments

@tacaswelltacaswelltacaswell approved these changes

@ksundenksundenksunden approved these changes

+2 more reviewers

@geofftgeofftgeofft left review comments

@zaniebzaniebzanieb left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

Projects

None yet

Milestone

v3.10.6

Development

Successfully merging this pull request may close these issues.

[ENH]: Gracefully handle python-build-standalone ImportError

6 participants

@timhoffm@geofft@zanieb@tacaswell@QuLogic@ksunden

[8]ページ先頭

©2009-2025 Movatter.jp