Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
FixAttributeError: module 'gi' has no attribute 'require_version'#30657
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
FixAttributeError: module 'gi' has no attribute 'require_version'#30657
Uh oh!
There was an error while loading.Please reload this page.
Conversation
heinrich5991 commentedOct 17, 2025
How can I add tests for this? @tacaswell I took the liberty and deviated from what I've originally proposed to lower the amount of code that gets executed in a |
heinrich5991 commentedOct 17, 2025
I'm not sure if the ubuntu-24.04-arm test failure is related to my PR. Can someone help me? |
rcomer commentedOct 17, 2025
That failure is happening on various PRs. Since it's a timeout error, I re-started the job to see if it passes on second attempt. |
| try: | ||
| gi.require_version | ||
| exceptAttributeErroraserr: | ||
| raiseImportError("The GTK3 backends require PyGObject")fromerr |
tacaswellOct 17, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Does the error message above need to be corrected then? I do not fully understand how PyGObject / gobject introspection splits itself up in either and upstream sense or the downstream packaging sense (which I assume different packagers make different choices?).
"No, this is the right error message in both cases" is perfectly good answer, but if we can make this a bit more precise that would be good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Does the error message above need to be corrected then?
I think it's the correct error as the remediation is (on Arch Linux) to installpython-gobject.import gi doesn't fail because other packages populate the /usr/lib/python3.13/site-packages/gi/ path, e.g. with /usr/lib/python3.13/site-packages/gi/overrides/Atspi.py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is likely a consequence of Python's new(ish) implicit namespace packages.
tacaswell left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
On the "does the machinery do what it should" front, 👍
I left one comment making the human facing error message more precise, but approving the PR so if the answer is "this is the best we can do", then we only need one more review.
tacaswell commentedOct 17, 2025
This is something where I'm ok with not adding an explicit test. We know that we can get an attribute error raised and have other tests that the machinery that catches the |
WeatherGod commentedOct 17, 2025 via email
One little nitpick. Should the ImportError be raised from `None` or `err`? …On Fri, Oct 17, 2025 at 1:12 PM Thomas A Caswell ***@***.***> wrote: *tacaswell* left a comment (matplotlib/matplotlib#30657) <#30657 (comment)> This is something where I'm ok with not adding an explicit test. We know that we can get an attribute error raised and have other tests that the machinery that catches the ImportError works correctly. The work to construct a test case with a half-installed pygobject and then maintain it going forward is in my judgement not worth the opportunity cost of spending that effort else where. — Reply to this email directly, view it on GitHub <#30657 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AACHF6AIO5CP3PAFULOUBI33YEPO5AVCNFSM6AAAAACJOKAIIOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMJWGQYDCMJXGI> . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***> |
heinrich5991 commentedOct 18, 2025
I'd think from |
heinrich5991 commentedOct 18, 2025
I have a different suggestion, maybe we could instead use Then we don't have to catch the |
heinrich5991 commentedOct 18, 2025
If you like the other approach, I can squash the commits. :) |
tacaswell commentedOct 20, 2025
I like the import-as approach better, more lines of change, but simplifies the logic. |
On Arch Linux, automatic backend selection fails when[`at-spi2-core`](https://archlinux.org/packages/extra/x86_64/at-spi2-core/files/)is installed but[`python-gobject`](https://archlinux.org/packages/extra/x86_64/python-gobject/files/)is not. Detect this by importign `gi.require_version` directly.```python>>> import matplotlib.pyplot as plt>>> plt.plot([0, 1], [0, 1])Traceback (most recent call last): File "<python-input-1>", line 1, in <module> plt.plot([0, 1], [0, 1]) ~~~~~~~~^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/matplotlib/pyplot.py", line 3838, in plot return gca().plot( ~~~^^ File "/usr/lib/python3.13/site-packages/matplotlib/pyplot.py", line 2785, in gca return gcf().gca() ~~~^^ File "/usr/lib/python3.13/site-packages/matplotlib/pyplot.py", line 1108, in gcf return figure() File "/usr/lib/python3.13/site-packages/matplotlib/pyplot.py", line 1042, in figure manager = new_figure_manager( num, figsize=figsize, dpi=dpi, facecolor=facecolor, edgecolor=edgecolor, frameon=frameon, FigureClass=FigureClass, **kwargs) File "/usr/lib/python3.13/site-packages/matplotlib/pyplot.py", line 551, in new_figure_manager _warn_if_gui_out_of_main_thread() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "/usr/lib/python3.13/site-packages/matplotlib/pyplot.py", line 528, in _warn_if_gui_out_of_main_thread canvas_class = cast(type[FigureCanvasBase], _get_backend_mod().FigureCanvas) ~~~~~~~~~~~~~~~~^^ File "/usr/lib/python3.13/site-packages/matplotlib/pyplot.py", line 369, in _get_backend_mod switch_backend(rcParams._get("backend")) ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/matplotlib/pyplot.py", line 411, in switch_backend switch_backend(candidate) ~~~~~~~~~~~~~~^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/matplotlib/pyplot.py", line 425, in switch_backend module = backend_registry.load_backend_module(newbackend) File "/usr/lib/python3.13/site-packages/matplotlib/backends/registry.py", line 317, in load_backend_module return importlib.import_module(module_name) ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/usr/lib/python3.13/importlib/__init__.py", line 88, in import_module return _bootstrap._gcd_import(name[level:], package, level) ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1387, in _gcd_import File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 1026, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/usr/lib/python3.13/site-packages/matplotlib/backends/backend_gtk4agg.py", line 4, in <module> from . import backend_agg, backend_gtk4 File "/usr/lib/python3.13/site-packages/matplotlib/backends/backend_gtk4.py", line 19, in <module> gi.require_version("Gtk", "4.0") ^^^^^^^^^^^^^^^^^^AttributeError: module 'gi' has no attribute 'require_version'```Fixesmatplotlib#30654.
7c07889 to3ecf087Compareheinrich5991 commentedOct 20, 2025
Squashed the commits. |
heinrich5991 commentedOct 20, 2025
Could someone retry the failed pipeline? I'm not sure if it's related to this PR, I'd guess "no". |
tacaswell left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Still approve of simplified version.
tacaswell commentedOct 20, 2025
Thanks! This still needs a second reviewer to merge it. |
ea40d72 intomatplotlib:mainUh oh!
There was an error while loading.Please reload this page.
QuLogic commentedOct 21, 2025
Thanks@heinrich5991! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again. |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free tosuggest an improvement. |
… attribute 'require_version'`
…3.10.xBackport PR#30657 on branch v3.10.x (Fix AttributeError: module 'gi' has no attribute 'require_version')
Uh oh!
There was an error while loading.Please reload this page.
On Arch Linux, automatic backend selection fails when
at-spi2-coreis installed butpython-gobjectis not. Detect this by importinggi.require_versiondirectly.Fixes#30654.
PR checklist