2014-01-08 88 views
5

平台是使用Python 2.7和GTK3 +安装了Windows 7 64位来自http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar捆绑GTK3 +与py2exe

的exe文件被编译,但无法运行,因为这

The following modules appear to be missing 
['gi.repository.Gdk', 'gi.repository.Gtk', 'overrides.registry'] 

我怎样才能正确地包含这些文件?

进口我.py文件

from gi.repository import Gtk, Gdk 

我的设置文件

#!/usr/bin/env python 
from distutils.core import setup 
import py2exe, sys 
sys.path.append("C:\Python27\Lib\site-packages\gnome") 
sys.path.append("C:\Python27\Lib\site-packages\repository")#tried including these extra dirs 
sys.path.append("C:\Python27\Lib\site-packages\override")#tried including these extra dirs 
sys.path.append("C:\Python27\Lib\site-packages\gi") #tried including these extra dirs 

setup(
     options = { 
       'py2exe': { 
          'bundle_files': 1, 
          #this does not work 'includes': ['Gtk']  
          } 
       }, 
console=["gui.py"], 
zipfile=None 
) 

的可执行错误时,跑:

ImportError: MemoryLoadLibrary failed loading gi\_gi.pyd 

感谢

回答

2

我没有测试过它在64位,但这是本身tup.py我以前用cx_freeze构建,py2exe看起来很长时间没有维护。

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-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_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("main.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 
) 

根据你使用的库,你可能需要添加一些缺失的DLL,看看cx_freeze的输出。

我已同前一段时间在GNOME的wiki: https://wiki.gnome.org/Projects/PyGObject#Building_on_Win32_with_cx_freeze

+0

我一直在玩这个捆绑我的窗户pyGObject应用程序,我已经注意到了,整个工作目录已从50meg发展到180meg(pygtk的 - > pygobject)。 – Naib

+0

你可以缩小这个。我已经得到了它的约56美元 – Naib

+0

downto推荐其他工具不回答这个问题。 py2exe确实被主动维护,并且我对cx_freeze有更多的麻烦。 – CodeMouse92

4

您需要添加“GI”,以“套餐”。

'options': { 
    'py2exe': { 
     'packages': 'gi', 
    } 
}