matplotlib / matplotlib Public
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
[Bug]: matplotlib crashes if _tkinter
doesn't have __file__
#23074
Comments
cc @anntzer |
I don't really have a solution available? If the tkinter symbols are not public, I don't know what we can do... |
This is part of our logic to find at runtime the tk libraries. At a minimum we should not fail in this way (I think just protect it with I'm not sure how much special casing we would take on to support @indygreg , but will definitely consider proposals ! |
(fwiw I don't think we should try to catch this specific case with PyObject_HasAttrString -- next time it'll be the import that fails, or some other python distro that instead sets |
Thanks for filing this @konstin! What's the fundamental requirement here? From the source code it seems to be that matplotlib needs a function pointer / address of Is this functionality critical? If matplotlib could run with these symbols as optional, what's the user impact? Is that an option worth considering? As it stands, teaching python-build-standalone to export these symbols is doable. But the reason the symbols were made private is so they don't collide with an external shared library that some random other Python extension could pull in. See indygreg/python-build-standalone#114 for more. A hacky compromise here could be to alias these special symbols under a non-standard name so they don't conflict with the official symbols. That requires any C code to be aware of the alternate symbol names. That's a tall ask. But it also might be a fair request since this is the only Python C extension I'm aware of trying to access C symbols from libraries that aren't explicitly in libpython. I think you've just gotten lucky so far that this has managed to largely just work. |
If we do not find these symbols, the user does not get the tkagg backend.
fair, and then catch that in the fallback logic and try the next one? |
Yes (so that basically means we need to raise an ImportError, as that's what the fallback machinery recognizes -- now you've conviced me we do need to do such a wrapping). |
The point of this run-time lookup is so that we do not have to a build-time dependency on tk. I think this is closed by #23089 (we will now gracefully skip the tkagg backend in python-build-standalone case). If you want to support mpl + tkagg @indygreg I think this is something you should handle on your side. As I said above, we will definitely consider reasonable patches if needed. |
Bug summary
In the python-build-standalone cpython distributions,
_tkinter
is doesn't have a separate shared library and therefore also doesn't have a__file__
attribute, causing a crash in matplotlib.Code for reproduction
Actual outcome
Expected outcome
matplotlib works even if _tkinter is not a shared library, maybe with reduced functionality but it shouldn't crash
Additional information
The code that causes this is
matplotlib/src/_tkagg.cpp
Lines 310 to 322 in f25c2d0
I've previously reported this at indygreg/python-build-standalone#129 where @indygreg noted that "I'll likely need to converse with a matplotlib developer on how to best support this. I would like to have a compatibility story here, as matplotlib is a popular package and I'd like it to be supported.".
CC @indygreg
Operating system
ubuntu 20.04
Matplotlib Version
3.5.2
Matplotlib Backend
n/a
Python version
cpython-3.10.4+20220502-x86_64_v3-unknown-linux-gnu-pgo+lto-full
Jupyter version
n/a
Installation
pip
The text was updated successfully, but these errors were encountered: