没有名为';gi&x27;在Python中GTK+;3教程你好世界

没有名为';gi&x27;在Python中GTK+;3教程你好世界,python,macos,gtk,Python,Macos,Gtk,我一直在努力学习本教程,但似乎无法正确安装。教程示例和结果位于底部。不过,很明显,我没有按照说明在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/Pro

我一直在努力学习本教程,但似乎无法正确安装。教程示例和结果位于底部。不过,很明显,我没有按照说明在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安装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'
3.7.1(默认,2018年11月28日11:51:54)
回溯(最近一次呼叫最后一次):
[Clang 10.0.0(Clang-1000.11.45.5)]
文件“/Users/Wes/Dropbox/Programming/Python/glade_againnn/tryit.py”,第5行,在
导入gi
ModuleNotFoundError:没有名为“gi”的模块
导入系统
打印(系统版本)
导入gi
gi.要求_版本(“Gtk”、“3.0”)
从gi.repository导入Gtkwindow
window=Gtk.window(title=“Hello World”)
window.show()
window.connect(“销毁”,Gtk.main_退出)
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'

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'
3.7.1(默认,2018年11月28日11:51:54)
回溯(最近一次呼叫最后一次):
[Clang 10.0.0(Clang-1000.11.45.5)]
文件“/Users/Wes/Dropbox/Programming/Python/glade_againnn/tryit.py”,第5行,在
导入gi
ModuleNotFoundError:没有名为“gi”的模块
我在virtualenv中尝试了这些步骤,然后又在没有virtualenv活动的情况下再次尝试了这些步骤


接下来我应该尝试什么?

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

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
如果您想与
Python
3.7.1一起使用,则需要安装
GTK
for
Python
3.7.1