Reputation: 1029
I have a small py program that using py27 & pygtk. I can freeze this this quite happily with cx_freeze.
I have been attempting to "port" it over to py33 & pygobject. This has been completed quite successfully and I am not trying to adapt my setup.py cx_freeze script to now "freeze" the application.
I am able to freeze a test application but when I then try to use my tweaked version I receive a ImportError. What I have done is I have made all the binary data go into a subdirectory (bin) to try to keep the root a bit less unclutter.
As mentioned this works fine with py27 & pygtk.
I have shrunk it downto a simple py and setup to demonstrate this:
TEST.py
########################################################################
import os
import sys
if getattr(sys,'frozen',False):
# if trap for frozen script wrapping
sys.path.append(os.path.join(os.path.dirname(sys.executable),'bin'))
sys.path.append(os.path.join(os.path.dirname(sys.executable),'bin\\etc'))
sys.path.append(os.path.join(os.path.dirname(sys.executable),'bin\\lib'))
sys.path.append(os.path.join(os.path.dirname(sys.executable),'bin\\share'))
sys.path.append(os.path.join(os.path.dirname(sys.executable),'bin\\library.zip'))
os.environ['TCL_LIBRARY'] = os.path.join(os.path.dirname(sys.executable),'bin\\tcl')
os.environ['TK_LIBRARY'] = os.path.join(os.path.dirname(sys.executable),'bin\\tk')
os.environ['MATPLOTLIBDATA'] = os.path.join(os.path.dirname(sys.executable),'bin\\mpl-data')
import gi
import gi.repository
from gi.repository import Gtk
#######################################################################
setup.py
########################################################################
from cx_Freeze import setup, Executable
import sys
import site
import os
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gnome")
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'
]
gtk_libs = ['etc', 'lib', 'share']
include_files = []
for dll in missing_dll:
include_files.append((os.path.join(include_dll_path, dll), dll))
for lib in gtk_libs:
include_files.append((os.path.join(include_dll_path, lib), lib))
includes = ['gi']
excludes = ['wx','email','pydoc_data','curses']
packages = ['gi']
sys.path.append(os.path.join(os.path.dirname(__file__), '.', 'bin'))
EXE1 = Executable(
script = "test.py",
initScript = None,
base = 'Console',
targetDir = "dist",
targetName = "test.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = True,
appendScriptToLibrary = False,
)
setup(
version = "9999",
description = "test",
author = "jrb",
name = "test",
options = {"build_exe": {"includes": includes,
"excludes": excludes,
"packages": packages,
'include_files':include_files,
"path": sys.path,
'append_script_to_exe':False,
'build_exe':"dist/bin",
'compressed':True,
'copy_dependent_files':True,
'create_shared_zip':True,
'include_in_shared_zip':True,
'optimize':2,
}
},
executables = [EXE1]
)
########################################################################
now when I run: /c/Python33/python -OO setup.py build and then execute dist/test.exe I have printed to the console:
ERROR:root:Could not find any typelib for Gtk Traceback (most recent call last): File "c:\Python33\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27, in exec(code, m.dict) File "test.py", line 19, in ImportError: cannot import name Gtk
I have checked and the typelib files exist but for whatever reason python & gi cannot find them. I thought it might be a missing path to girepository but that didn't fix it. Any ideas?
Upvotes: 3
Views: 936
Reputation: 1029
os.environ['GI_TYPELIB_PATH'] = os.path.join(os.path.dirname(sys.executable),'bin\\lib\girepository-1.0')
Upvotes: 2