PyInstaller Kivy ClockApp 示例问题
Posted
技术标签:
【中文标题】PyInstaller Kivy ClockApp 示例问题【英文标题】:PyInstaller Kivy ClockApp Example Issue 【发布时间】:2016-12-29 17:56:24 【问题描述】:===编辑结束===
哇!
感谢以下建议和 (8) 小时的编译和重新编译,我能够通过多种方式解决我的问题:
了解如何需要 Pyinstaller 挂钩才能正确调用模块。
确保所有输入文件和输出文件文件位置都存在于同一驱动器上。在我的公司,我们的系统环境变量默认设置为映射的网络驱动器,我必须确保默认情况下所有用户环境变量设置都映射到“C:\”,以便 pyinstaller 会选择它。这包括将我的 cmd.exe 设置为正确的驱动器和目标文件输出。
在我构建了正确的 .spec 文件之后,确保所有必要的文件(.JPG、.kv、.PNG)文件都在 /dist 文件夹中
我能够打包 kivy 网站上的 PongGame 示例以及下面提到的 Book/Chapter 2 的 Paint_App 示例。
再次感谢。
===最后编辑结束===
===再次编辑===
根据下面的建议,我尝试运行显示错误日志的程序。
但是,从 cmd.exe 运行甚至不会吐出错误日志。
但是,.kivy 会保留所有错误日志。
[INFO ] Logger: Record log in H:\.kivy\logs\kivy_16-08-30_29.txt
[INFO ] Kivy: v1.9.1
[INFO ] Python: v3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)]
[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 <b'4.2.0'>
[INFO ] GL: OpenGL vendor <b'NVIDIA Corporation'>
[INFO ] GL: OpenGL renderer <b'Quadro K3000M/PCIe/SSE2'>
[INFO ] GL: OpenGL parsed version: 4, 2
[INFO ] GL: Shading version <b'4.20 NVIDIA via Cg compiler'>
[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 ] Base: Start application main loop
[INFO ] Base: Leaving application in progress...
[WARNING ] stderr: Traceback (most recent call last):
[WARNING ] stderr: File "kivy\properties.pyx", line 754, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:11776)
[WARNING ] stderr: KeyError: 'time'
[WARNING ] stderr:
[WARNING ] stderr: During handling of the above exception, another exception occurred:
[WARNING ] stderr:
[WARNING ] stderr: Traceback (most recent call last):
[WARNING ] stderr: File "mainClock.py", line 40, in <module>
[WARNING ] stderr: File "site-packages\kivy\app.py", line 828, in run
[WARNING ] stderr: File "site-packages\kivy\base.py", line 487, in runTouchApp
[WARNING ] stderr: File "site-packages\kivy\core\window\window_sdl2.py", line 619, in mainloop
[WARNING ] stderr: File "site-packages\kivy\core\window\window_sdl2.py", line 362, in _mainloop
[WARNING ] stderr: File "site-packages\kivy\base.py", line 327, in idle
[WARNING ] stderr: File "site-packages\kivy\clock.py", line 515, in tick
[WARNING ] stderr: File "site-packages\kivy\clock.py", line 647, in _process_events
[WARNING ] stderr: File "site-packages\kivy\clock.py", line 406, in tick
[WARNING ] stderr: File "mainClock.py", line 32, in update
[WARNING ] stderr: File "kivy\properties.pyx", line 757, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:11882)
[WARNING ] stderr: AttributeError: 'super' object has no attribute '__getattr__'
===再次编辑结束===
编辑:
查看构建文件夹,我看到一个warnmainClock.txt,其中包含大量可笑的行,说我缺少模块。
这是否意味着我没有正确链接到我的 python 文件夹库?
例如:
missing module named _collections.deque - imported by _collections, collections, threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named _thread.stack_size - imported by _thread, threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named _thread._local - imported by _thread, threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named threading.current_thread - imported by threading, _threading_local, C:\Python34x86\Examples\kivy\mainClock.py
missing module named threading.RLock - imported by threading, _threading_local, bz2, multiprocessing.dummy, C:\Python34x86\Examples\kivy\mainClock.py
missing module named sys.modules - imported by sys, dummy_threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named _dummy_threading - imported by dummy_threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named _dummy_threading.__all__ - imported by _dummy_threading, dummy_threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named dummy_threading.RLock - imported by dummy_threading, bz2, C:\Python34x86\Examples\kivy\mainClock.py
missing module named dummy_threading.local - imported by dummy_threading, numpy.distutils.misc_util, C:\Python34x86\Examples\kivy\mainClock.py
missing module named time.monotonic - imported by time, subprocess, threading, queue, C:\Python34x86\Examples\kivy\mainClock.py
missing module named time.time - imported by time, subprocess, threading, queue, kivy.uix.behaviors.button, kivy.uix.behaviors.compoundselection, kivy.effects.kinetic, kivy.uix.filechooser, kivy.input.motionevent, kivy.input.postproc.doubletap, kivy.input.postproc.tripletap, multiprocessing.managers, multiprocessing.synchronize, C:\Python34x86\Examples\kivy\mainClock.py
missing module named Queue - imported by kivy.compat, C:\Python34x86\Examples\kivy\mainClock.py
missing module named time.strftime - imported by time, kivy.logger, C:\Python34x86\Examples\kivy\mainClock.py
missing module named kivy.app.App - imported by kivy.app, kivy.uix.scrollview, kivy.uix.screenmanager, kivy.uix.filechooser, kivy.uix.textinput, kivy.uix.settings, kivy.lang, kivy.support, kivy.core.window.window_sdl2, kivy.uix.video, kivy.uix.carousel, kivy.uix.treeview, kivy.uix.colorpicker, kivy.uix.splitter, kivy.uix.slider, kivy.uix.codeinput, C:\Python34x86\Examples\kivy\mainClock.py
编辑结束
我目前正在从 Mark Vasilkov 的“Kivy Blueprints”一书中学习 Kivy。
我正在尝试将第 1 章中的 ClockApp 打包为练习。该代码在 python 命令行中完美运行。但是,我在使用 pyinstaller 创建 Windows 包时遇到了问题。
源代码和.kv文件在这里https://github.com/mvasilkov/kb/tree/master/1_Clock
我已经效仿https://kivy.org/docs/guide/packaging-windows.html
我使用以下命令从命令提示符创建了一个 Windows 包:
C:\Python34x86\Scripts\pysintaller C:\Python34x86\Examples\kivy\mainClock.py --noconsole
然后我使用规范文件构建:
C:\Python34x86\Scripts\pyinstaller H:\mainClock.spec
这两个命令都按照指定在我的 H 盘中创建 /dist 文件。
当我从 \mainClock.py 构建后访问 EXE 文件时,我收到错误:
当我在构建 .spec 文件后运行 EXE 文件时,我得到以下信息:
.spec 文件如下所示:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['C:\\Python34x86\\Examples\\kivy\\mainClock.py'],
pathex=['H:\\'],
binaries=None,
datas=None,
hiddenimports=[],
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='mainClock',
debug=True,
strip=False,
upx=True,
console=False )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='mainClock')
我认为问题不是源于源头,有人可以指出我做错了什么吗?
【问题讨论】:
写.spec correctly怎么样? 我已多次阅读说明并尝试使用下面给出的脚本进行构建。但是,我没有得到任何结果。如果你知道我到底做错了什么,请指出来。 关键是要包括二进制文件,正如答案中已经提到的那样。您可以粘贴在答案中使用规范构建后获得的完整错误日志吗?如果没有控制台,请在 cmd.exe (...> mainClock) 中运行该应用程序,它应该提供更多信息。我认为您可能仍然缺少这些二进制文件,因为它们可能未包含在 %path% 变量中。 谢谢KeeWeeUsr,虽然没有直接从命令行吐出错误日志,但我找到了kivy日志并贴出了错误。 尝试在安装 python 的同一驱动器上制作应用程序(将源移动到C:
并在 C:
上构建,在规范中也重写 'H:\\'
。它找不到日志告诉你的 kivy 模块。
【参考方案1】:
下面的代码可能对你有帮助吗?
# -*- mode: python -*-
import os
from os.path import join
from kivy import kivy_data_dir
from kivy.deps import sdl2, glew
from kivy.tools.packaging import pyinstaller_hooks as hooks
block_cipher = None
kivy_deps_all = hooks.get_deps_all()
kivy_factory_modules = hooks.get_factory_modules()
datas = []
# list of modules to exclude from analysis
excludes = ['Tkinter', '_tkinter', 'twisted', 'pygments']
# list of hiddenimports
hiddenimports = kivy_deps_all['hiddenimports'] + kivy_factory_modules
# binary data
sdl2_bin_tocs = [Tree(p) for p in sdl2.dep_bins]
glew_bin_tocs = [Tree(p) for p in glew.dep_bins]
bin_tocs = sdl2_bin_tocs + glew_bin_tocs
# assets
kivy_assets_toc = Tree(kivy_data_dir, prefix=join('kivy_install', 'data'))
source_assets_toc = []
assets_toc = [kivy_assets_toc, source_assets_toc]
tocs = bin_tocs + assets_toc
a = Analysis(['C:\\Python34x86\\Examples\\kivy\\mainClock.py'],
pathex=['H:\\'],
binaries=None,
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
runtime_hooks=[],
excludes=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,
name='mainClock',
exclude_binaries=True,
debug=False,
strip=False,
upx=True,
console=False)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
*tocs,
strip=False,
upx=True,
name='mainClock')
【讨论】:
比尔,谢谢你的回复。我已经根据上述构建了规范。但是,我仍然收到“无法执行脚本 mainClock”。以上是关于PyInstaller Kivy ClockApp 示例问题的主要内容,如果未能解决你的问题,请参考以下文章
Pyinstaller 难以通过 Kivy 构建 FileChooserListView
如何从我的 kivy 应用程序(Pyinstaller)获取 Windows 可执行文件?
使用 pyinstaller 打包后 Kivy 应用程序崩溃