在 py2exe 的 PyGTK 程序中显示图像
我使用 PyGTK 在 Python 中编写了一个 GUI 应用程序,并希望将其作为可执行文件分发,为此我使用 py2exe。当我运行程序时,我收到以下警告,
GdkPixbuf-WARNING **: Cannot open pixbuf loader module file 'gtk-2.0\gdk-pixbuf.loaders': No such file or directory
并且即使 dist\etc\gtk-2.0\gdk-pixbuf.loaders
存在,我的图像也不会显示。
如何将我的程序打包为 Windows exe 并使用这些图像?
I have written a GUI app in Python using PyGTK and want to distribute it as an executable, for which I'm using py2exe. When I run my program, I get the following warning
GdkPixbuf-WARNING **: Cannot open pixbuf loader module file 'gtk-2.0\gdk-pixbuf.loaders': No such file or directory
and my images do not display, even though dist\etc\gtk-2.0\gdk-pixbuf.loaders
exists.
How can I package my program as a Windows exe and use these imagines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 py2exe,则必须将 gtk+(等、共享、lib)打包到项目中与 exe 处于同一级别的位置:
示例目录结构:
您有该目录结构吗?
If you are using py2exe, you must pack gtk+ (etc, shared, lib) inside your project at the same level of your exe:
Sample directory structure:
Do you have that directory structure?
标准答案是将GTK+的bin等、share和lib目录复制到
项目的 dist 目录是正确的(但我看到有人破坏了 [1] 并且
列表中缺少 bin),毕竟:
至少,您需要所有 3 个绑定包,并且由于它们。
如果底层平台不可用(.dll 文件、
配置文件,简而言之:整个shebang)。这就是 GTK+ 的原因
bin等、share和lib需要复制到项目的dist目录中。
然而,我几年前发布到 [1] 的 setup.py 片段是微妙的
不完整。正确的版本应该是:
记下 zipfile 和 dest_base 的值。有了这些选项
你的.exe、一堆.pyd文件和library.zip都是在
py2exe 的 dist/bin 目录。然后当你将 GTK+ 的目录复制到 py2exe 的目录时
您的可执行文件位于 dist 目录中,紧邻 libgtk-win32-2.0.0.dll 等
本来应该如此。如果不执行上述操作,则 PATH 环境配置错误
变量可能会干扰您的 .dll 文件(有时不兼容)
py2exe 的可执行文件加载。
所以对于上面的setup.py文件,dist正确的目录结构应该是
看起来像这样:
当你使上述工作正常时,你会发现加载图像
就可以了,你可以开始考虑省略一些部分
共享/(例如您不想要/不需要的翻译文件)等
mvg,
迪特
[1] http://www.py2exe.org/index.cgi/Py2exeAndPyGTK
编辑 2011/07/05:修复了 PyGObject 2.28/PyGTK 2.24 的包含选项。
如果您仅使用 PyGObject 2.28,则包含选项具有
包含“glib、gio、gobject”。如果您使用 PyGTK 那么它需要:
'glib、gio、gobject、cairo、atk、pango、pangocairo、gtk'。
The standard answer of copying GTK+'s bin, etc, share and lib directory to the
project's dist directory is correct (but I see somebody has vandalized [1] and
bin is missing from the list), after all:
At a minimum, you need all 3 of those bindings packages and due to their
nature they are useless if the underlying platform is not available (.dll files,
configuration files, in short: the whole shebang). That's why GTK+'s
bin, etc, share and lib need to be copied to your project's dist directory.
The setup.py fragment I posted a couple of years ago to [1] is however subtly
incomplete. The correct version should have been:
Take note of the values for zipfile and dest_base. With these options
your .exe, a bunch of .pyd files and library.zip are all created in
py2exe's dist/bin directory. Then when you copy GTK+'s directories to py2exe's
dist directory your executable lives right next to libgtk-win32-2.0.0.dll et al
as it should be. If you don't do the above, a misconfigured PATH environment
variable might interfere with what (sometimes incompatible) .dll files your
py2exe'd executable loads.
So for the above setup.py file, the correct directory structure of dist should
look like this:
When you get the above working correctly you will find that loading images
just works and you can start thinking about leaving out some parts of
share/ (like the translation files you don't want/need) etc.
mvg,
Dieter
[1] http://www.py2exe.org/index.cgi/Py2exeAndPyGTK
Edit 2011/07/05: fixed the includes option for PyGObject 2.28/PyGTK 2.24.
If you're only using PyGObject 2.28 the includes option has
to contain 'glib, gio, gobject'. If you're using PyGTK then it needs:
'glib, gio, gobject, cairo, atk, pango, pangocairo, gtk'.