【问题标题】:Creating a small python program with cx_Freeze and pyGTK使用 cx_Freeze 和 pyGTK 创建一个小型 Python 程序
【发布时间】:2014-10-26 01:30:33
【问题描述】:

我正在编写一个使用 python 2.7 和 pygtk 的小型测试程序。 我也会用 Glade

我需要用 cx_freeze 冻结它。

这是我的小程序:

import gtk

win = gtk.Window()
win.connect("delete-event", gtk.main_quit)
win.show_all()
gtk.main()

这是我的设置:

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, "gnome")



## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-win32-2.0-0.dll',
               'libgdk-win32-2.0-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_path = os.path.join(site_dir, "gtk-2.0\\runtime\include\libglade-2.0\\")
glade_folder = 'glade'
# glade_folder = os.path.join(site_dir, "gtk-2.0\\")
# glade_folder += "runtime\include\libglade-2.0\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_path, 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("hello.py",
               base=base
    )
]

buildOptions = dict(
    compressed=False,
    includes=["gi"],
    packages=["gi"],
    include_files=include_files
    )

setup(
    name="test_gtk3_app",
    author="my name",
    version="1.0",
    description="GTK 3 test",
    options=dict(build_exe=buildOptions),
    executables=executables
)

我运行这个命令:

python setup_fr.py 构建

因此,创建了一个名为“build”的文件夹,其中包含各种文件和目录。但是,当我运行程序“hello.exe”时,会出现这个错误:

Traceback (most recent call last):   File "C:\Python27\lib\site-packages\cx_freeze-4.3.3-py2.7-win32.egg\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)   File "hello.py", line 1, in <module>   File "C:\Python27\lib\site-packages\gtk-2.0\gtk\__init__.py", line 30, in <module>
    import gobject as _gobject   File "C:\Python27\lib\site-packages\gobject\__init__.py", line 26, in <module>
    from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \   File "C:\Python27\lib\site-packages\glib\__init__.py", line 22, in <module>
    from glib._glib import *   File "ExtensionLoader_glib__glib.py", line 22, in <module>   File "ExtensionLoader_glib__glib.py", line 14, in __bootstrap__ ImportError: DLL load failed: Could not find the specified module.

我查看了“Build”文件夹以查看是否缺少与 gobject 相关的内容,并找到了“gobject._gobject.pyd”、“libcairo-gobject-2.dll”和“GObject-2.0.typelib”文件。我不确切知道哪个文件仍然丢失。

谁能帮我找出问题所在?

【问题讨论】:

    标签: python-2.7 gtk pygtk cx-freeze glade


    【解决方案1】:

    转到 gnome 目录,该目录本身位于 site-packages 目录中,然后从该目录手动复制所有 .dll 文件(不是嵌套文件)到您的 build/your-application-dir/ 目录。 它会起作用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 2013-08-19
      • 1970-01-01
      • 2018-02-23
      • 2021-08-15
      相关资源
      最近更新 更多