python-2.7 - 将 GTK3+ 与 cx_freeze 捆绑在一起

标签 python-2.7 exe gtk3 cx-freeze pygobject

平台是使用 python 2.7 和 GTK3 安装的 Windows 7 64 位 http://games.2g2s.de/?page_id=223和 PyGobject 从这里 http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar

我使用了 wiki 上提供的脚本:

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-2.dll',
           'libcairo-gobject-2.dll',
           'libgdk_pixbuf-2.0-0.dll',
           'libpango-1.0-0.dll',
           'libpangocairo-1.0-0.dll',
           'libpangoft2-1.0-0.dll',
           'libpangowin32-1.0-0.dll',
           'libffi-6.dll',
           'libfontconfig-1.dll',
           'libfreetype-6.dll',
           'libgio-2.0-0.dll',
           'libglib-2.0-0.dll',
           'libgmodule-2.0-0.dll',
           'libgobject-2.0-0.dll',
           'libpng15-15.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("materii.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
)

exe已编译但无法运行,因此

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", in <module>
    exec code in m.__dict__
  File "materii.py", line 2, in <module>
  File "C:\Python27\lib\site-packages\gi\__init__.py", line 27, in <module>
    from ._gi import _API
  File "ExtensionLoader_gi__gi.py", line 22, in <module>
  File "ExtensionLoader_gi__gi.py", line 14, in __bootstrap__
ImportError: DLL load failed: The specified module could not be found.

materii.py 的第 2 行是

from gi.repository import Gtk

你能帮帮我吗?

最佳答案

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

关于python-2.7 - 将 GTK3+ 与 cx_freeze 捆绑在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22134768/

相关文章:

python - 如何从 python 3.5 脚本创建独立的可执行文件?

excel - 有没有办法将 Excel 文件嵌入到我的可执行 (exe) 文件中?

gotk3,带有自定义小部件的笔记本附加页面并将其取回

python - 在 Python GTK3 中设置条目背景颜色并设置回默认值的最佳方法

python - 如何使用 python 从文件夹中读取 xml 文件?

Python xlsxwriter TypeError : tuple indices must be integers, 不是 str

python - 在开放的 ERP 7 日历中添加我们国家的节假日

python - 将结尾为 "\"的字符串添加到字符串列表的所有元素

java - exe4j高dpi设置

c - 编辑 gtkcellrenderertext