Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 使用cx_Freeze和pyGTK创建一个小型python程序_Python 2.7_Gtk_Pygtk_Cx Freeze_Glade - Fatal编程技术网

Python 2.7 使用cx_Freeze和pyGTK创建一个小型python程序

Python 2.7 使用cx_Freeze和pyGTK创建一个小型python程序,python-2.7,gtk,pygtk,cx-freeze,glade,Python 2.7,Gtk,Pygtk,Cx Freeze,Glade,我正在编写一个使用Python2.7和pygtk的小测试程序。 我也会用林间空地 我要把这个冷冻起来 这是我的小程序: 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 fol

我正在编写一个使用Python2.7和pygtk的小测试程序。 我也会用林间空地

我要把这个冷冻起来

这是我的小程序:

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
)
这是我的设置:

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安装程序\u 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.
Traceback(最后一次调用):文件“C:\Python27\lib\site packages\cx\u freeze-4.3.3-py2.7-win32.egg\cx\u freeze\initscripts\Console.py”,第27行,在
exec(代码,m.uuu dict_uuu)文件“hello.py”,第1行,在文件“C:\Python27\lib\site packages\gtk-2.0\gtk\uuu init_uuuuu.py”的第30行中
将gobject作为gobject文件“C:\Python27\lib\site packages\gobject\\uuuuu init\uuuuuu.py”导入,第26行,在
从glib import spawn\u async、idle\u add、timeout\u add、timeout\u add\u seconds文件“C:\Python27\lib\site packages\glib\\uuuuuu init\uuuuuuu.py”,第22行,在
从glib.\u glib import*文件“ExtensionLoader\u glib\u glib.py”,第22行,在文件“ExtensionLoader\u glib\u\u glib.py”,第14行,在uuuu bootstrap\uuuuuu导入错误:DLL加载失败:找不到指定的模块。
我查看了“Build”文件夹,查看是否缺少与gobject相关的内容,并找到了“gobject.\u gobject.pyd”“libcairo-gobject-2.dll”和“gobject-2.0.typelib”文件。我不知道到底是哪个文件丢失了


有人能帮我找出问题所在吗?

转到gnome目录,它本身位于站点包的目录中,并手动将所有.dll文件(不是嵌套文件)从该目录复制到构建/应用程序目录中。 它会起作用的