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
pyplot: Fix exception in _backend_selection
during import [backport to 1.4.x]
#3541
Conversation
Fixes #2901 |
@@ -91,8 +91,9 @@ def _backend_selection(): | |||
if not PyQt5.QtWidgets.qApp.startingUp(): | |||
# The mainloop is running. | |||
rcParams['backend'] = 'qt5Agg' | |||
elif 'gtk' in sys.modules and not backend in ('GTK', 'GTKAgg', | |||
'GTKCairo'): | |||
elif 'gtk' in sys.modules \ |
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.
Please use ()
line continuation, not \
.
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.
Done, thanks.
_backend_selection
during import_backend_selection
during import [backport to 1.4.x]
3a21db1
to
85004a5
Compare
cc @fariza as a gtk expert. I seem to recall that we have some of the new-style imports someplace in the code. I may be out-of-scope for this PR, but I think if |
Well there's
but I confess I don't understand the original code. My reading of I wrote a little script to test this:
and the Gtk2 style bindings equivalent:
They both give the same result:
I agree that this these larger issues should be out-of-scope for this pull request. For one thing I imagine you wouldn't want to backport a patch that may change the selection of the backend to 1.4.0. |
if the new style introspection GObject python bindings are in use. With pygobject >= 3.13.4 the following: from gi.repository import GObject from matplotlib import pyplot causes an exception to be raised: > AttributeError: When using gi.repository you must not import static modules > like "gobject". Please change all occurrences of "import gobject" to "from > gi.repository import GObject". See: > https://bugzilla.gnome.org/show_bug.cgi?id=709183 It is not valid to use both non-introspection based and introspection based PyGObject in the same process. Backend probing will `import gobject` (i.e. the non-introspection bindings) if it sees that the 'gtk' module is loaded. Unfortunately it wouldn't check if this was the pygi or old-style gtk module. This commit adds this check avoiding the exception. This check was added to PyGObject in [d704033][1] [1]: https://git.gnome.org/browse/pygobject/commit/?id=d704033
85004a5
to
9194d3c
Compare
I don't really understand this code either, I was hoping you did! |
Sorry to come late to the party. |
Would it be ok to have this patch merged? It might not implement the full-solution that we'd like, but it does fix the crash and is unlikely to have any undesirable side-effects. |
The error message is pretty clear, so it seems reasonable to me. Any objection if I cherry-pick this to v1.4.x @tacaswell? |
No problem with cherry-picking it back from me. |
Sorry. I didn't have time to check it. I'm in the middle of some Angular mess
|
Merged with commit 236355c into v1.4.x. f9feefe...236355c |
if the new style introspection GObject python bindings are in use. With pygobject >= 3.13.4 the following:
causes an exception to be raised:
It is not valid to use both non-introspection based and introspection based PyGObject in the same process. Backend probing will
import gobject
(i.e. the non-introspection bindings) if it sees that the 'gtk' module is loaded.Unfortunately it wouldn't check if this was the pygi or old-style gtk module. This commit adds this check avoiding the exception.
This check was added to PyGObject in d704033