У меня есть небольшая программа на python, использующая python 3.4.Однако я не могу заставить его работать в .exe с помощью Cx_freeze на Windows.
Я получаю сообщение об ошибке:
\build\exe.win-amd64-3.4>lcp.exe
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "LCP.py", line 5, in <module>
File "C:\Python34\lib\site-packages\gi\__init__.py", line 118, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available
При попытке запустить .exe с помощью cmd, как обычно, его запускс двойным щелчком я получаю только экран, который открывается и вылетает.
Программа использует gi.repository и имеет этот код в начале:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk,Gdk
мой файл setup.py выглядит следующим образомсейчас:
import os
from cx_Freeze import setup, Executable
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk,Gdk
build_exe_options = { "include_msvcr": True}
# Frozen executables made by build_exe need to have everything that GTK
# loads at runtime available under the root where the built .exe goes.
common_include_files = []
# On MSYS2's MINGW64/32 enrironments, the DLLs we want are in PATH.
# Typically this means /mingw64/bin/libwhatever.dll. An alternative way
# of forming the list of required DLLs would be to parse the relevant
# .gir files (see below). However, libpangowin32-1.0-0.dll wouldn't be
# listed.
required_dll_search_paths = os.getenv("PATH", os.defpath).split(os.pathsep)
required_dlls = [
'libgtk-3-0.dll',
'libgdk-3-0.dll',
'libepoxy-0.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',
'libatk-1.0-0.dll',
]
for dll in required_dlls:
dll_path = None
for p in required_dll_search_paths:
p = os.path.join(p, dll)
if os.path.isfile(p):
dll_path = p
break
assert dll_path is not None, \
"Unable to locate {} in {}".format(
dll,
dll_search_path,
)
common_include_files.append((dll_path, dll))
# We need the .typelib files at runtime.
# The related .gir files are in $PREFIX/share/gir-1.0/$NS.gir,
# but those can be omitted at runtime.
required_gi_namespaces = [
"Gtk-3.0",
"Gdk-3.0",
"cairo-1.0",
"Pango-1.0",
"GObject-2.0",
"GLib-2.0",
"Gio-2.0",
"GdkPixbuf-2.0",
"GModule-2.0",
"Atk-1.0",
]
# Packages that need to be bundled go here.
common_packages = [
"gi","gtk-3.0", "Gdk-3.0" # always seems to be needed
# "cairo", # Only needed (for foreign structs) if no "import cairo"s
]
ejecutable = Executable(
script ="LCP.py",
#compress = True,
#copyDependenFile = True,
#appendScriptToExe =True,
#appendScriptToLibrary = True,
#icon = "imagen"
)
includes =['os','gi','gi.overrides']
packages = ['gi', 'os']
include_files= ['respuestasFrecuentes.txt'] #archivos extra q no sean .py
setup(
name = 'Respuestas Frecuentes',
author = 'Irina Marcano',
version = '0.1.0',
description = 'facilidad para modificar tus respuestas recientes',
executables= [ejecutable],
options = {"build_exe":{
"includes": includes,
"packages": packages,
"optimize": 2,
"include_files": include_files,
#"include_msvcr": include_msvcr,
} }
)
Этот setup.py занял у меня несколько дней, так как в начале у него были проблемы.Пока не работает даже копирование dll из библиотек в папке.Я застрял с этой ошибкой сверху, и я понятия не имею, что делать сейчас.Я использую Windows 10, на Windows 8 он также не будет работать и выдает ту же ошибку, как указано в начале.Открытие программы на ее .py работает отлично, открытие даже с использованием Python 3.6 работает, за исключением нескольких ошибок, так как отсутствуют gi и gtk.
, чтобы отметить, что при использовании python setup.py build, я получаю это сообщение:
Missing modules:
? UserList imported from pygtkcompat.pygtkcompat
? __main__ imported from bdb, pdb
? _dummy_threading imported from dummy_threading
? _posixsubprocess imported from subprocess
? _winreg imported from platform
? ce imported from os
? gi.repository.Atk imported from pygtkcompat.pygtkcompat
? gi.repository.GLib imported from gi.overrides.Dee, gi.overrides.GObject, gi.overrides.Gio, pygtkcompat.pygtkcompat
? gi.repository.GObject imported from gi.overrides.GExiv2, gi.overrides.Gedit, gi.overrides.Gtk, gi.overrides.Vips, pygtkcompat.generictreemodel, pygtkcompat.pygtkcompat
? gi.repository.GUdev imported from pygtkcompat.pygtkcompat
? gi.repository.Gdk imported from lcp__main__, pygtkcompat.pygtkcompat
? gi.repository.GdkPixbuf imported from pygtkcompat.pygtkcompat
? gi.repository.GdkX11 imported from gi.overrides.Gdk
? gi.repository.Gio imported from gi.overrides.Ggit, pygtkcompat.pygtkcompat
? gi.repository.GooCanvas imported from pygtkcompat.pygtkcompat
? gi.repository.Gst imported from gi.overrides.GstPbutils, pygtkcompat.pygtkcompat
? gi.repository.GstAudio imported from pygtkcompat.pygtkcompat
? gi.repository.GstBase imported from pygtkcompat.pygtkcompat
? gi.repository.GstController imported from pygtkcompat.pygtkcompat
? gi.repository.GstInterfaces imported from pygtkcompat.pygtkcompat
? gi.repository.GstPbutils imported from pygtkcompat.pygtkcompat
? gi.repository.GstVideo imported from pygtkcompat.pygtkcompat
? gi.repository.Gtk imported from lcp__main__, pygtkcompat.generictreemodel, pygtkcompat.pygtkcompat
? gi.repository.Pango imported from pygtkcompat.pygtkcompat
? gi.repository.PangoCairo imported from pygtkcompat.pygtkcompat
? gi.repository.Poppler imported from pygtkcompat.pygtkcompat
? gi.repository.Vte imported from pygtkcompat.pygtkcompat
? gi.repository.WebKit imported from pygtkcompat.pygtkcompat
? gi.repository.cairo imported from gi.overrides.Gdk
? grp imported from shutil, tarfile
? java.lang imported from platform
? org.python.core imported from copy
? os.path imported from os, pkgutil, py_compile, shutil, unittest.util
? posix imported from os
? pwd imported from http.server, posixpath, shutil, tarfile, webbrowser
? termios imported from tty
? vms_lib imported from platform
This is not necessarily a problem - the modules may not be needed on this platform.
Я пока не знаю, как удалить большинство из них, так как моя программа использует только gtk и gdk, к которым мне нужен gi для доступа.