py::attribute_error: module 'matplotlib.ft2font' has no attribute '__path__' gets thrown but something something got messed up during unwinding and it resulted in segfault and ended up hidden.
I see the attribute error, but it does not get turned into a segfault:
(segfault) /tmp
✔ 10:55:58 [yennefer] @ python
Python 3.13.2 (main, Feb 4 2025, 00:00:00) [GCC 14.2.1 20250110 (Red Hat 14.2.1-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.ft2font
>>> matplotlib.ft2font.__path__
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
matplotlib.ft2font.__path__
AttributeError: module 'matplotlib.ft2font' has no attribute '__path__'. Did you mean: '__name__'?
>>>
Still digging. Currently dealing with libunwind. Pretty sure it's not MPL, but I'm not done just yet. There's an instance of iterate_phdr_function ptr being null, when it should point to a libc's dl_iterate_phdr(). I'm gonna get back to you after I know more, feel free to ignore until then.
TLDR; rebuilding with clang fixes the issue, but I'm not sure about the underlying cause.
In case someone's affected by the same issue and is determined to actually solve it:
When handling an exception passing C/Python boundary, libunwind tried to call a function stored in a struct as a pointer and in this case, the pointer was null. libunwind is not at fault, I tried various versions and even switched to LLVM's libunwind to make sure. Said struct seems to be at least partially based on info passed from libgcc_s.so and it was already malformed when received.
The fixed, clang-compiled, mpl still links to the exact same libgcc_s.so, so I can't say that was the problem either. In any case it's almost certainly not a matplotlib problem, perhaps pybind11.
MPL, yes. I tried recompiling python, libunwind and other possible suspects with different compilers or compiler options (all at once, to prevent possible incompatibilities) and that achieved nothing. Copying clang'ed ft2font.cpython-313-x86_64-linux-gnu.so into my venv served as a workaround.
OK, that's both good and bad news. We can't really get rid of the exceptions in ft2font until the deprecations expire in 3.12, or possibly if pybind/pybind11#1853 were implemented first. But since it will also fail in other cases, that means I won't spend any time trying to workaround the deprecations.
I can perhaps suspect that pybind/pybind11#5359 might be related, but I don't know that anything in pytest(-cov) would have loaded anything else that uses pybind11. But possibly this issue is still related as something may still not be specifying exception ABI somehow.
pybind11 has a new major version. Might be worth giving it a try. Def. ping me once you have a version that's compatible with it, I'll see if it solves the issue.
We've already been building main and v3.10.x against it since it came out, so I don't think there would be anything preventing you testing v3.10.3 with it. That being said, I did open #30291 to take advantage of the new features in pybind11 v3 which you may want to try, though I don't think there's anything exception-related there.
I should also add, that the exceptions from ft2font interferes with the use of ASAN, and forces an exit on the first exception , at least with default configurations
I've been investigating this again due to a downstream report in Fedora. This only affected ppc64le and no other architectures. It turns out that the problem there was that libunwind was compiled with its C++ exception support enabled on the one architecture (due to some autodetection).
Upstream has also disabled C++ exception support by default, but this isn't in a release yet, so I suggest that wherever you got libunwind from probably is leaving it at the default autodetect and/or enabling it explicitly.
Activity
mmatous commented on Apr 28, 2025
Bisected. Bad commit: 9e02512
py::attribute_error: module 'matplotlib.ft2font' has no attribute '__path__' gets thrown but something something got messed up during unwinding and it resulted in segfault and ended up hidden.
tacaswell commented on Apr 28, 2025
Interesting. Curious if this is an mpl bug, a pytest-cov bug, or a pybind11 bug.
tacaswell commented on Apr 28, 2025
That said, I can not reproduce this with wheels and Python from fedora
mmatous commented on Apr 28, 2025
Do you get the same query for __path__ attr that triggers the exception? And it proceeds to be handled just fine?
tacaswell commented on Apr 28, 2025
I see the attribute error, but it does not get turned into a segfault:
(segfault) /tmp ✔ 10:55:58 [yennefer] @ python Python 3.13.2 (main, Feb 4 2025, 00:00:00) [GCC 14.2.1 20250110 (Red Hat 14.2.1-7)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import matplotlib.ft2font >>> matplotlib.ft2font.__path__ Traceback (most recent call last): File "<python-input-1>", line 1, in <module> matplotlib.ft2font.__path__ AttributeError: module 'matplotlib.ft2font' has no attribute '__path__'. Did you mean: '__name__'? >>>QuLogic commented on Apr 28, 2025
FWIW, I also tried this in valgrind, and didn't see any memory issues.
mmatous commented on Apr 28, 2025
Still digging. Currently dealing with libunwind. Pretty sure it's not MPL, but I'm not done just yet. There's an instance of iterate_phdr_function ptr being null, when it should point to a libc's dl_iterate_phdr(). I'm gonna get back to you after I know more, feel free to ignore until then.
mmatous commented on Apr 30, 2025
TLDR; rebuilding with clang fixes the issue, but I'm not sure about the underlying cause.
In case someone's affected by the same issue and is determined to actually solve it:
When handling an exception passing C/Python boundary, libunwind tried to call a function stored in a struct as a pointer and in this case, the pointer was null. libunwind is not at fault, I tried various versions and even switched to LLVM's libunwind to make sure. Said struct seems to be at least partially based on info passed from libgcc_s.so and it was already malformed when received.
The fixed, clang-compiled, mpl still links to the exact same libgcc_s.so, so I can't say that was the problem either. In any case it's almost certainly not a matplotlib problem, perhaps pybind11.
Thank you for your help.
tacaswell commented on Jul 7, 2025
@mmatous To verify the thing you recompiled with clang was Matplotlib (not CPython)?
mmatous commented on Jul 7, 2025
MPL, yes. I tried recompiling python, libunwind and other possible suspects with different compilers or compiler options (all at once, to prevent possible incompatibilities) and that achieved nothing. Copying clang'ed ft2font.cpython-313-x86_64-linux-gnu.so into my venv served as a workaround.
QuLogic commented on Jul 7, 2025
Does your gcc default to -fno-exceptions or some similar option?
19 remaining items
QuLogic commented on Jul 18, 2025
OK, that's both good and bad news. We can't really get rid of the exceptions in ft2font until the deprecations expire in 3.12, or possibly if pybind/pybind11#1853 were implemented first. But since it will also fail in other cases, that means I won't spend any time trying to workaround the deprecations.
I can perhaps suspect that pybind/pybind11#5359 might be related, but I don't know that anything in pytest(-cov) would have loaded anything else that uses pybind11. But possibly this issue is still related as something may still not be specifying exception ABI somehow.
We've already been building main and v3.10.x against it since it came out, so I don't think there would be anything preventing you testing v3.10.3 with it. That being said, I did open #30291 to take advantage of the new features in pybind11 v3 which you may want to try, though I don't think there's anything exception-related there.
PhilipDeegan commented on Jul 27, 2025
I should also add, that the exceptions from ft2font interferes with the use of ASAN, and forces an exit on the first exception , at least with default configurations
QuLogic commented on Jul 10, 2026
The module-level __getattr__ was removed in #31879, so there should no longer be any exceptions at import time with 3.12.
QuLogic commented on Aug 20, 2026
I've been investigating this again due to a downstream report in Fedora. This only affected ppc64le and no other architectures. It turns out that the problem there was that libunwind was compiled with its C++ exception support enabled on the one architecture (due to some autodetection).
Upstream has also disabled C++ exception support by default, but this isn't in a release yet, so I suggest that wherever you got libunwind from probably is leaving it at the default autodetect and/or enabling it explicitly.