简体   繁体   English

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

[英]Cannot import WebKit in python via gi.repository on Mac High Sierra

I have been trying to prepare a development where I can use GTK and WebKit in python for the past few days.过去几天,我一直在尝试准备一个可以在 python 中使用 GTK 和 WebKit 的开发。 I have given up on ubuntu and now I just want to focus on mac first.我已经放弃了 ubuntu,现在我只想先专注于 mac。 I have installed the pygobject3 and I can load the GTK 3.0.我已经安装了 pygobject3 并且可以加载 GTK 3.0。 But I can't get the WebKit working.但我无法让 WebKit 工作。 The error message is this,错误信息是这样的

>>> 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

I have tried with "WebKit2", "WebKit3" etc...我尝试过“WebKit2”、“WebKit3”等...

I have also downloaded and build the WebKit from webkit.org ,and it did nothing.我还从webkit.org下载并构建了 WebKit,但它什么也没做。

I would love to have some guidance over all to properly install it, I can upload any test you wish me to run and promptly update it here.我很想得到一些正确安装它的指导,我可以上传您希望我运行的任何测试,并在此处及时更新。

Thank you very much!非常感谢!

The following is the current way of importing WebKit:以下是目前导入WebKit的方式:

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

from gi.repository import WebKit2

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

Here is an example that renders Google starting page:这是一个呈现 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()

Finally, the PyGObject API Reference can be found here .最后,可以在此处找到 PyGObject API 参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM