[英]Cannot Include gi.repository.Gtk in py2exe
I have a project in Python 3.4 and GTK+ 3. I'm on Windows XP SP3 32-bit (VirtualBox). 我在Python 3.4和GTK + 3中有一个项目。我在32位Windows XP SP3(VirtualBox)上。
I need to compile down to an executable using py2exe. 我需要使用py2exe编译为可执行文件。 (Do NOT suggest cx_freeze. It has ten times the problems on this project than py2exe). (不要建议cx_freeze。此项目的问题比py2exe的问题大十倍)。
My setup.py is as follows. 我的setup.py如下。
#!/usr/bin/python
from setuptools import setup
import py2exe
setup(name="Redstring",
version="2.0",
description="REDundant STRING generator",
author="MousePaw Labs",
url="http://www.mousepawgames.com/",
maintainer_email="info@mousepawgames.com",
data_files=[("", ["redstring.png", "redstring_interface.glade"])],
py_modules=["redstring"],
windows=[{'script':'redstring.py'}],
options={"py2exe":{
"unbuffered": True,
"compressed":True,
"bundle_files": 1,
'packages':['gi.repository'],
}},
zipfile=None
)
When I run it via C:\\Documents and Settings\\Jason\\Desktop\\redstring2>python setup.py py2exe
, I get the following output (in full). 当我通过C:\\Documents and Settings\\Jason\\Desktop\\redstring2>python setup.py py2exe
运行它时,我得到以下输出(完整)。
running py2exe
running build_py
1 missing Modules
------------------
? gi.repository.Gtk imported from __SCRIPT__
Building 'dist\redstring.exe'.
C:\Documents and Settings\Jason\Desktop\redstring2>
The actual script, redstring.py
, runs without a hitch in my Windows environment. 实际的脚本redstring.py
在Windows环境中运行顺利。 In that, I have the following (working) line of code: from gi.repository import Gtk
That is ALL I import from gi.repository in the entire project. 在那,我有以下(有效的)代码行: from gi.repository import Gtk
这就是我在整个项目中从gi.repository导入的全部。
If I swap the line in setup.py to 'packages':['gi'],
, the error output switches to about 24-some-odd missing modules, all of them belonging to gi.repository. 如果我将setup.py中的行交换为'packages':['gi'],
错误输出将切换到大约24多个缺少的模块,所有模块都属于gi.repository。 If I try and import "Gtk" or "gi.repository.Gtk" in either 'packages':
or 'includes':
, I get an error that the file in question being imported cannot be found. 如果我尝试在'packages':
或'includes':
导入“ Gtk”或“ gi.repository.Gtk”,则会收到错误消息,提示找不到正在导入的文件。
I spent eight hours on #python (IRC channel) today, and no one could solve this. 我今天在#python(IRC频道)上花了八个小时,没有人能解决这个问题。 I need this packaged down to a Windows binary this week. 我本周需要将此打包为Windows二进制文件。
NOTE: This question is not a duplicate; 注意: 这个问题不是重复的; while it is a similar issue, it is a) not the same error message, and b) neither answer solves the question in any way. 虽然这是一个类似的问题,但它是a)错误消息不同,并且b)答案都不能以任何方式解决问题。
I solved this by, first of all, downgrading to Python 2.7. 我首先通过降级到Python 2.7来解决了这个问题。 (GTK+ 3.8 is still fine.) py2exe apparently has known issues with Python 3. (GTK + 3.8仍然可以。)py2exe显然具有Python 3的已知问题。
Second, I switched... 其次,我切换了...
options={"py2exe": {
"bundle_files": 1,
}
to 至
options={"py2exe": {
"bundle_files": 3,
}
For some reason, py2exe cannot include certain files needed to run the gi library when 'bundle_files'
is set to 1
or 2
. 由于某些原因,当'bundle_files'
设置为1
或2
时,py2exe无法包含运行gi库所需的某些文件。
The full setup.py that works with py2exe for my project can be found on GitHub . 可以在GitHub上找到适用于我的项目的py2exe的完整setup.py。 I run it on cmd with python setup.py py2exe
. 我使用python setup.py py2exe
在cmd上运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.