I am trying to import GDK to my program however I continue to get an error
No module named GDK
Do you know how I can fix this? Since it was working before I already tried import gtk.GDK
and import GDK.
I have installed PyGTK and PyGDK is part of of it pyGTK.
Try:
import gtk.gdk
(note: small letters)
Related
How can I avoid the following error:
GTK module not found in Python (PyCharm), please see the snippet below.
This answer hasn't helped.
(Still cannot find gtk in pip.)
if you are using pyhon 3.0+ then import this library like this: from gi.repository import Gtk
I am trying to build an exe using PyInstaller (with Python 2.7) and have been stumped. My python code uses the modules wx, matplotlib, basemap (a part of matplotlib), and pylab. There are others, but these seem to be the main ones.
I have installed PyInstaller and then i did:
python pyinstaller.py C:/Python27/Convertthisfile.py
It goes through the whole process, but when i try to run the final executable, it comes up with the error:
"No module named PyQt4.QtCore"
I have installed PyQt GPL 4.9.1 for Python 2.7. However, I have no idea where PyQt is even being used in my code. I don't specify it anywhere that i know of.
Anyone have any thoughts? Nothing I do seems to work. I have even tried the GUI2EXE.py -- i can't get py2exe, pyinstaller, or cx_freeze to work.
HELP!
I have added my code below to hopefully help. To answer the comments, yes, my code is located in C:\Python27. I have no problem "building" it with pyinstaller, but the above error comes up when i try to run the given executable. I have searched the code and do not see any use of PyQt4.
When i run cx_freeze, i have issues with the basemap data files -- they do not seem to be included in the ".zip" when i build it. Also, none of my modules seem to get included either.
Here is what i import for my code (some of these functions are my own -- mainly the last ones listed).
import wx
import time
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
from datetime import datetime
import wx.calendar as cal
import wx.lib.mixins.listctrl as listmix
from pylab import *
from decimal import *
import adodbapi
import annote_new
import cPickle as pickle
import calc_dist
import Game_Score
import Calculate_Distance
import Duplicate_Finder
import copy
Hopefully this clears things up?
I'm nearly new to python and new to gtk.
I just can't figure out, why I get this error message:
self.builder.get_object("checkstatus").set_from_stock("gtk-yes", Gtk.ICON_SIZE_BUTTON)
.......
AttributeError: 'gi.repository.Gtk' object has no attribute 'ICON_SIZE_BUTTON'
At the beginning I'm importing:
import pygtk
pygtk.require('2.0')
from gi.repository import Gtk
So the problem is that gtk has no no attribute called 'ICON_SIZE_BUTTON'?
But when I look at the documentation it says so...
http://developer.gnome.org/pygtk/2.22/class-gtkimage.html#method-gtkimage--set-from-stock
I would appreciate any help. Thanks!
Well, there's a few things going on.
For GTK+ 3 which uses PyGObject, you use from gi.repository import Gtk and then use Gtk.IconSize.BUTTON.
For GTK+ 2 which uses PyGTK you use import pygtk and import gtk and then use gtk.ICON_SIZE_BUTTON.
In other words, you're mixing up versions. PyGTK (GTK 2) was replaced by PyGObject and something called "gobject introspection" in GTK 3. Check out this tutorial: http://python-gtk-3-tutorial.readthedocs.org/en/latest/index.html
My situation is Aptana eclipse plug-in installed and working properly.
If I from gi.repository import Gtk the code completion I'm used to from import gtk is gone. Any solutions or is it just a bug?
My interim solution is keeping an import gtk\ngtk. in a clipboard manager and dropping it in when I need hints.
Yes, there is!
You should add gi to the forced builtins and you'll get a code completion:
Go to the Window->Preferences, PyDev->Interpreter python section and add gi to the "Forced builtin" tab for each interpreter you would like to use Gtk3.
More about this:
http://pydev.org/manual_101_interpreter.html
from gi.repository import Gtk
is not same like
import gtk
With the statement "
from gi.repository import Gtk
your are importing Gtk 3. With
import gtk
your are importing Gtk 2.
I would say that you code completion doesn't know Gtk 3.
maybe useful:
Tutorial for Gtk 3 http://readthedocs.org/docs/python-gtk-3-tutorial/en/latest/index.html
http://live.gnome.org/PyGObject
I have troubles understanding gi.repository
I use this contruction in my code
from gi.repository import Gtk
But if I want to use some component I get import error
I searched and I got it worked for some components, like GtkSource, Vte, GLib, ...
So my code is like
from gi.repository import Gtk, GtkSource, Vte, GLib
Everything worked fine, but if I want to add matplotlib to draw on my canvas I get and error
enter code/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: specified class size for type `PyGtkGenericCellRenderer' is smaller than the parent type's `GtkCellRenderer' class size
from gtk import _gtk
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: assertion `node != NULL' failed
from gtk import _gtk
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_ascii_strncasecmp: assertion `s2 != NULL' failed
from gtk import _gtk
Segmentation fault (core dumped) here
How can I get matplotlib working with gi.repository?
Thank you
It seems that the support for Gtk3 it's been added recently. I guess it will take some time till it's available in the main distributions.
The best solution would be to download and install the latest version.
As a workaround to avoid installing stuff in my Ubuntu 11.10 I have dowloaded backend_gtk3.py and backend_gtk3agg.py files and imported directly like:
from gi.repository import Gtk
from matplotlib.figure import Figure
from backend_gtk3agg import FigureCanvasGTK3Agg as FigCanvas
I had to change backend_gtk3agg.py line 6 where it says:
import backend_agg
with
from matplotlib.backends import backend_agg
, so it can import the module from my installation.
So far it works for me, but I understand this solution can't work with different versions of matplotlib.
That's a very good question. I'm afraid the answer might be "you can't." Matplotlib's GTK backend is written for PyGTK, the old-style Python bindings for GTK. The gi.repository package is the new-style Python bindings. I don't know one way or the other whether they can mix or not, but your results seem to indicate they can't.