简体   繁体   English

Windows上的Python3和GTK3

[英]Python3 and GTK3 on Windows

I am currently trying to use GTK3 and Python3 for GUI development. 我目前正在尝试使用GTK3和Python3进行GUI开发。

Everything is working fine while doing this on my Ubuntu device, but as I want to be able to have Windows executables later, I need to set these tools up on Windows 7. 在我的Ubuntu设备上执行此操作时,一切工作都很好,但是由于我希望以后能够拥有Windows可执行文件,因此我需要在Windows 7上设置这些工具。

I have Python 3.4.4 (64 Bit) installed on my system and tried solutions from other posts on Stackoverflow to be able to use GTK with it, but I was not able to get it to work. 我的系统上安装了Python 3.4.4(64位),并尝试了Stackoverflow上其他文章的解决方案以使其能够使用GTK,但我无法使其正常工作。

When trying to import Gtk ( import gi and from gi.repository import Gtk ) on the Python shell, the following error occurs: 尝试在Python Shell上导入Gtk( import gifrom gi.repository import Gtk )时,发生以下错误:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2158, 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 "C:\Python34\lib\site-packages\gi\importer.py", line 100, in find_module
    'introspection typelib not found' % namespace)
ImportError: cannot import name Gtk, introspection typelib not found

What I have installed at the moment: 我目前安装的内容:

Which is the best way to get a working set of Python3 and GTK3 on Windows? 在Windows上获得Python3和GTK3的工作集的最佳方法是哪一种? (As far as I have seen it is not possible to create Windows executables using Ubuntu.) (据我所知,不可能使用Ubuntu创建Windows可执行文件。)

You need only to install Python 3.4 and the PyGObject project on sourceforge (the one you mentioned in your post). 您只需要在sourceforge(您在帖子中提到的那个)上安装Python 3.4和PyGObject项目。 This setup must work on Windows, because it works for me. 此设置必须在Windows上可以使用,因为它适用于我。

Maybe you missed to check the Gtk3 libraries during installation of PyGObject (this is a frequent error). 也许您在安装PyGObject的过程中错过了检查Gtk3库的操作(这是一个常见错误)。

You don't need msys2 at all to use PyGObject in Python. 您完全不需要msys2在Python中使用PyGObject。

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

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