Skip to content
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

Trouble importing GTK when pyplot is imported #2901

Closed
uberscientist opened this issue Mar 15, 2014 · 4 comments
Closed

Trouble importing GTK when pyplot is imported #2901

uberscientist opened this issue Mar 15, 2014 · 4 comments

Comments

@uberscientist
Copy link

>>> import matplotlib.pyplot
>>> from gi.repository import Gtk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/gi/__init__.py", line 27, in <module>
    from ._gi import _API
ImportError: could not import gobject (error was: ImportError('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".',))

And if I import GTK first then pyplot I get a segfault.

  • OS: Arch Linux x86_64
  • Python:
    Python 2.7.6 (default, Feb 26 2014, 12:07:17) [GCC 4.8.2 20140206 (prerelease)] on linux2
  • GTK: 3.10.7
@jenshnielsen
Copy link
Member

Which backend does pyplot use. Try setting the backend with matplotlib.use() before importing pyplot

@uberscientist
Copy link
Author

By default it's using "GTKAgg" (matplotlib.get_backend())

I tried to set it explicitly: matplotlib.use("GTKAgg") ... but I still get the same error when trying to import Gtk:

'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".'

I did a search through matplotlib code and saw occurrences of "import gobject", should I go through and change them to the suggestion and see if that works, maybe do a pull request if it does?

edit:... Or maybe I could try and use import gtk instead of from gi.repository import Gtk ... I really don't know the difference at the moment edit2: Things didn't work when I did import gtk (sorry for being such a noobie)

@uberscientist
Copy link
Author

Ok, I built matplotlib from git, and it uses Qt4Agg as the default backend which worked, but I was also able to set it GTK3Agg (I didn't know there was a GTK 3 backend.) and that also worked, but plain GTKAgg crashes.

Thanks for the hint @jenshnielsen

@mdboom
Copy link
Member

mdboom commented Mar 17, 2014

GtkAgg uses the old pygobject wrappers, which are not compatible with the gobject-introspection wrappers. Mixing the two is sure to lead to this madness ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants