无法在 Mac High Sierra 上通过 gi.repository 在 python 中导入 WebKit

Sen*_*Sen 5 python macos webkit pygobject python-3.x

在过去的几天里,我一直在尝试准备一个可以在 python 中使用 GTK 和 WebKit 的开发。我已经放弃了ubuntu,现在只想先专注于mac。我已经安装了pygobject3并且可以加载GTK 3.0。但我无法让 WebKit 工作。错误信息是这样的,

>>> import gi
>>> from gi.repository import WebKit
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 888, in _find_spec
AttributeError: 'DynamicImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/gi/importer.py", line 127, in find_module
    'introspection typelib not found' % namespace)
ImportError: cannot import name WebKit, introspection typelib not found
Run Code Online (Sandbox Code Playgroud)

我尝试过“WebKit2”、“WebKit3”等......

我还从webkit.org下载并构建了 WebKit ,但它什么也没做。

我很想获得一些正确安装它的指导,我可以上传您希望我运行的任何测试并立即在此处更新。

非常感谢!

Tob*_*tte -2

以下是目前导入WebKit的方式:

import gi
gi.require_version('WebKit2', '4.0')

from gi.repository import WebKit2
Run Code Online (Sandbox Code Playgroud)

所需的 Debian/Ubuntu 软件包是:python3-gi gir1.2-webkit2-4.0 libwebkit2gtk-4.0-37

以下是呈现 Google 起始页的示例:

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')

from gi.repository import Gtk, WebKit2

window = Gtk.Window()
window.set_default_size(800, 600)
window.connect("destroy", Gtk.main_quit)

scrolled_window = Gtk.ScrolledWindow()
webview = WebKit2.WebView()
webview.load_uri("https://google.com")
scrolled_window.add(webview)

window.add(scrolled_window)
window.show_all()
Gtk.main()
Run Code Online (Sandbox Code Playgroud)

最后,可以在此处找到 PyGObject API 参考。