我使用PyInstaller在Windows 10上构建了一个.exe。当我运行可执行文件时,会打开一个窗口,但它不显示任何小部件,只显示空白屏幕。据我所知,输出没有显示任何错误。使用python 2.7(Enthought Canopy)和Kivy 1.9.1。当我运行原始源文件时,一切都运行良好;它只是失败的.exe。
我的.spec文件如下所示:
# -*- mode: python -*-
from kivy.deps import sdl2, glew, gstreamer
block_cipher = None
a = Analysis(['C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\PhoenixKv.py'],
pathex=['C:\\Users\\Christiaan\\Documents\\Phoenix'],
binaries=None,
datas=[('C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\dev_ids.json', '.'), ('C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\ref_ids.json', '.')],
hiddenimports=['sqlalchemy.ext.hybrid'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='phoenix',
debug=True,
strip=False,
upx=False,
console=True )
coll = COLLECT(exe, Tree('C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p'),
a.binaries,
a.zipfiles,
a.datas + [('dev_ids.json', 'C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\', 'DATA'), ('ref_ids.json', 'C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\', 'DATA')],
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=False,
name='phoenix')
运行时的输出是:
PyInstaller Bootloader 3.x
LOADER: executable is C:\Users\Christiaan\Documents\Phoenix\dist\phoenix\phoenix.exe
LOADER: homepath is C:\Users\Christiaan\Documents\Phoenix\dist\phoenix
LOADER: _MEIPASS2 is NULL
LOADER: archivename is C:\Users\Christiaan\Documents\Phoenix\dist\phoenix\phoenix.exe
LOADER: No need to extract files to run; setting extractionpath to homepath
LOADER: SetDllDirectory(C:\Users\Christiaan\Documents\Phoenix\dist\phoenix)
LOADER: Already in the child - running user's code.
LOADER: Python library: C:\Users\Christiaan\Documents\Phoenix\dist\phoenix\python27.dll
LOADER: Loaded functions from Python library.
LOADER: Manipulating environment (sys.path, sys.prefix)
LOADER: sys.prefix is C:\Users\CHRIST~1\DOCUME~1\Phoenix\dist\phoenix
LOADER: Setting runtime options
LOADER: Initializing python
LOADER: Overriding Python's sys.path
LOADER: Post-init sys.path is C:\Users\Christiaan\Documents\Phoenix\dist\phoenix
LOADER: Setting sys.argv
LOADER: setting sys._MEIPASS
LOADER: importing modules from CArchive
LOADER: extracted struct
LOADER: callfunction returned...
LOADER: extracted pyimod01_os_path
LOADER: callfunction returned...
LOADER: extracted pyimod02_archive
LOADER: callfunction returned...
LOADER: extracted pyimod03_importers
LOADER: callfunction returned...
LOADER: Installing PYZ archive with Python modules.
LOADER: PYZ archive: out00-PYZ.pyz
LOADER: Running pyiboot01_bootstrap.py
LOADER: Running pyi_rth_win32comgenpy.py
LOADER: Running pyi_rth__tkinter.py
LOADER: Running pyi_rth_pkgres.py
LOADER: Running pyi_rth_kivy.py
LOADER: Running pyi_rth_mplconfig.py
LOADER: Running pyi_rth_mpldata.py
LOADER: Running pyi_rth_gstreamer.py
LOADER: Running pyi_rth_qt4plugins.py
Qt: Untested Windows version 10.0 detected!
LOADER: Running PhoenixKv.py
Purge log fired. Analysing...
Purge 5 log files
Purge finished!
[INFO ] [Logger ] Record log in C:\Users\Christiaan\.kivy\logs\kivy_16-02-08_23.txt
[INFO ] [Kivy ] v1.9.1
[INFO ] [Python ] v2.7.6 |CUSTOM| (default, Sep 15 2014, 17:36:35) [MSC v.1500 64 bit (AMD64)]
[INFO ] [Factory ] 179 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [OSC ] using <thread> for socket
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] OpenGL version <4.5.13397 Compatibility Profile Context 0>
[INFO ] [GL ] OpenGL vendor <ATI Technologies Inc.>
[INFO ] [GL ] OpenGL renderer <AMD Radeon HD 8870M>
[INFO ] [GL ] OpenGL parsed version: 4, 5
[INFO ] [GL ] Shading version <4.40>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2
Successfully added file types.
Successfully added file types.
platform: Windows
[INFO ] [Base ] Start application main loop
答案 0 :(得分:1)
我遇到了同样的问题,并通过将.kv文件复制到dist文件夹来解决它。
cp -R C:/Users/Ben/Documents/OpenCV_HummingbirdsMotion/MotionMeerkat/MotionMeerkat.kv dist/main/
这也可以通过将.kv作为数据对象添加到spec文件来实现。基本上空白屏幕说,我知道有一个kivy应用程序,但我没有小部件。
答案 1 :(得分:0)
我知道这是一篇老文章,但是,我想我会提供更多见识。
如果您尝试使用–-onefile并仅制作一个文件,则仅将.kv文件移动到目录中对于您来说不是一个好选择。
我所做的是使用.pv将.kv文件内容嵌入python本身中
from kivy.lang import Builder
Builder.load_string("""
Your kivy content
""")
在我运行命令之前,将main.py
移到它自己的文件夹中,并将其重命名为main_em.py
之类的东西
python -m PyInstaller --onefile --windowed --name "myApp" "./main_em.py"
我之所以将其移到新文件夹中是因为,如果您尝试仅将程序作为python文件运行,它将堆叠两个相同的布局,因此基本上看起来您具有双重视野。
重命名并不是真正需要的,但是,我想保持代码库整洁。
尽管我不确定100%,但是我认为PyInstaller不知道如何处理.kv文件,因此,您只需要将其移动到文件夹中即可。但是,如果将其嵌入到python中,那么它就在python代码中。
将.kv文件嵌入到python代码中以实现可维护性并不是一个好习惯,但是,在这种情况下,由于将其打包,因此没有关系。
我处理工作流程的方式就是像在其他情况下一样在您的kviy项目上进行工作,并且需要打包时。您只需要复制并粘贴到main_em.py中,然后在main_em.py上运行PyInstaller。
这样,您可以遵循惯例和最佳实践,也不必在打包后将.kv文件移动到目录中。两全其美。
我希望这对其他人有帮助,这是我有史以来的第一篇文章。
答案 2 :(得分:0)
我正在查看一些文档,我认为您也可以执行以下操作:
Builder.load_file("./filename.kv")
这样,您就不必执行我在其他帖子中建议的操作。
只要记住那是您从python运行它,就必须注释掉Builder.load_file行。