3

我正在尝试在 ubuntu 12.04 上的 Eclipse Helios 中使用 PyDev 2.7.1 构建 GTK+ 应用程序。但是 Python 找不到类 gobject.GObject。我安装了我能找到的任何 gobject 库并尝试了几个外部库路径,就像这些 post pydev issue with gobjectHow to resolve these unresolved imports in PyDev (eclipse)? .

但到目前为止一切正常。有谁知道解决方法/解决方案?

问候CK

  import pygtk
  pygtk.require("2.0")
  import gobject

  class MyClass(gobject.GObject):
  ...

进口

  from gi.repository import GObject

不工作。

我还在 Eclipse 中的 PYTHONPATH 中添加了 /usr/lib/pyshared/python2.7,其中 gtk-2.0、gi 和 gobject 模块位于其中,但没有任何区别。

我也为解释器添加了一个强制内置的 gi,但没有效果。

这里报告了一个错误http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=649861,但自 pygobject 3.0.2-4 以来它已得到解决。我的 python-gobject 版本是 3.2.2-1

导入适用于在 PyDev 和终端中执行的测试脚本:

from gi.repository import GObject, Gtk

class Test(GObject.GObject):
    def __init__(self):
        GObject.GObject.__init__(self)
        print ("test")

    def main(self):
        print ("Import has worked")

print (__name__)
if __name__ == '__main__':    
    test = Test()
    test.main()

当我将此应用于 MyClass(GObject.GObject) 类时,出现以下错误:

ImportError: could not import gobject (error was: ImportError('When using gi.repository you must not import static modules like "gobject". Please change all of "import gobject" to "from gi.repository import GObject".', ))

没有import gobject,只有from gi.repository import GObject

4

1 回答 1

1

我终于找到了。

import gobject


class MyClass(gobject.GObject):

def __init__(self, channelstrip, name, s_type, mainWin):
    gobject.GObject.__init__(self)
于 2013-01-15T15:47:08.823 回答