2014-01-08 86 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', 
    } 
}