Python 捆绑GTK3和x2B;使用py2exe
平台是Windows 7 64位,使用python 2.7和GTK3+,安装于 由于此原因,exe已编译但无法运行Python 捆绑GTK3和x2B;使用py2exe,python,gtk,py2exe,pygobject,Python,Gtk,Py2exe,Pygobject,平台是Windows 7 64位,使用python 2.7和GTK3+,安装于 由于此原因,exe已编译但无法运行 The following modules appear to be missing ['gi.repository.Gdk', 'gi.repository.Gtk', 'overrides.registry'] 如何正确地包含这些文件 在my.py文件中导入 from gi.repository import Gtk, Gdk 我的安装文件 #!/usr/bin/env p
The following modules appear to be missing
['gi.repository.Gdk', 'gi.repository.Gtk', 'overrides.registry']
如何正确地包含这些文件
在my.py文件中导入
from gi.repository import Gtk, Gdk
我的安装文件
#!/usr/bin/env python
from distutils.core import setup
import py2exe, sys
sys.path.append("C:\Python27\Lib\site-packages\gnome")
sys.path.append("C:\Python27\Lib\site-packages\repository")#tried including these extra dirs
sys.path.append("C:\Python27\Lib\site-packages\override")#tried including these extra dirs
sys.path.append("C:\Python27\Lib\site-packages\gi") #tried including these extra dirs
setup(
options = {
'py2exe': {
'bundle_files': 1,
#this does not work 'includes': ['Gtk']
}
},
console=["gui.py"],
zipfile=None
)
运行时的可执行文件错误:
ImportError: MemoryLoadLibrary failed loading gi\_gi.pyd
谢谢我还没有在64位上测试过它,但这是我使用cx\u freeze构建的setup.py,py2exe看起来很长时间没有维护
from cx_Freeze import setup, Executable
import os, site, sys
## Get the site-package folder, not everybody will install
## Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gtk")
## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-3-0.dll',
'libgdk-3-0.dll',
'libatk-1.0-0.dll',
'libcairo-gobject-2.dll',
'libgdk_pixbuf-2.0-0.dll',
'libjpeg-8.dll',
'libpango-1.0-0.dll',
'libpangocairo-1.0-0.dll',
'libpangoft2-1.0-0.dll',
'libpangowin32-1.0-0.dll',
'libgnutls-26.dll',
'libgcrypt-11.dll',
'libp11-kit-0.dll'
]
## We also need to add the glade folder, cx_freeze will walk
## into it and copy all the necessary files
glade_folder = 'glade'
## We need to add all the libraries too (for themes, etc..)
gtk_libs = ['etc', 'lib', 'share']
## Create the list of includes as cx_freeze likes
include_files = []
for dll in missing_dll:
include_files.append((os.path.join(include_dll_path, dll), dll))
## Let's add glade folder and files
include_files.append((glade_folder, glade_folder))
## Let's add gtk libraries folders and files
for lib in gtk_libs:
include_files.append((os.path.join(include_dll_path, lib), lib))
base = None
## Lets not open the console while running the app
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable("main.py",
base=base
)
]
buildOptions = dict(
compressed = False,
includes = ["gi"],
packages = ["gi"],
include_files = include_files
)
setup(
name = "test_gtk3_app",
author = "Gian Mario Tagliaretti",
version = "1.0",
description = "GTK 3 test",
options = dict(build_exe = buildOptions),
executables = executables
)
根据您使用的库的不同,您可能需要添加一些缺少的dll,请查看cx\U freeze的输出
不久前,我在gnome的wiki上发布了同样的消息:
您需要在“包”中添加“gi”
我一直在使用它来捆绑我的pyGObject windows应用程序,我注意到整个工作目录已从50meg增长到180meg(pygtk-->pyGObject)。您可以缩小它。我已经把它降到了56%左右,但推荐另一个工具并不能回答这个问题。py2exe确实是积极维护的,我在cx_冻结方面遇到了更多的麻烦。@JasonMc92感谢您的评论,如果我的评论没有用,并且您有一个更好的py2exe解决方案,请随意发布您的代码,就像我做的那样。@gianmt,老实说,我还在处理它。(他们在我的项目中都是非常难相处的)我只是想让你知道很多SE上的人不会认为这是一个好的方式来推荐另一个工具而不是回答问题。如果您觉得cx_freeze会更好,建议它可能确实有帮助,但它最好作为您答案中的注释或旁注,而不是作为您答案的整体,因为它将问题从未回答列表中删除,降低实际问题被解决的机会。
'options': {
'py2exe': {
'packages': 'gi',
}
}