Python GTK + 3教程Hello World中没有名为“ gi”的模块

时间:2018-12-23 01:37:03

标签: python macos gtk

https://python-gtk-3-tutorial.readthedocs.io/en/latest/install.html

我一直在尝试遵循本教程,但似乎无法正确安装。教程示例和结果位于底部。显然,我没有按照说明在MacOS Mojave上安装所需的模块。

我遵循的步骤是:

brew install GTK+3
brew install gobject-introspection
brew install PyGObject
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 \
    /Users/Wes/Dropbox/Programming/Python/glade_againnn/tryit.py

尽管这不在本教程中,但我尝试了pip install PyGObject并收到了很长的错误消息:

Command "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/vf/x732mfwj4nvf5g_mntsyw97h0000gp/T/pip-install-xfgd22p9/PyGObject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/vf/x732mfwj4nvf5g_mntsyw97h0000gp/T/pip-record-3tko684k/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/vf/x732mfwj4nvf5g_mntsyw97h0000gp/T/pip-install-xfgd22p9/PyGObject/

错误消息是:

3.7.1 (default, Nov 28 2018, 11:51:54) 
Traceback (most recent call last):
[Clang 10.0.0 (clang-1000.11.45.5)]
  File "/Users/Wes/Dropbox/Programming/Python/glade_againnn/tryit.py", line 5, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'

import sys
print(sys.version)

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtkwindow
window = Gtk.Window(title="Hello World")

window.show()
window.connect("destroy", Gtk.main_quit)
Gtk.main()

错误消息是:

3.7.1 (default, Nov 28 2018, 11:51:54) 
Traceback (most recent call last):
[Clang 10.0.0 (clang-1000.11.45.5)]
  File "/Users/Wes/Dropbox/Programming/Python/glade_againnn/tryit.py", line 5, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'

我已经在virtualenv中尝试了这些步骤,然后又没有激活virtualenv。

接下来我应该尝试什么?

1 个答案:

答案 0 :(得分:4)

您已经安装了两个Python版本(3.6和3.7.1)。 GTK使用的是:

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6

如果要与GTK 3.7.1一起使用,请安装Python