PyInstaller 3.2.1 与 Kivy 1.10.0 pyz 语法错误并且不打包
Posted
技术标签:
【中文标题】PyInstaller 3.2.1 与 Kivy 1.10.0 pyz 语法错误并且不打包【英文标题】:PyInstaller 3.2.1 with Kivy 1.10.0 pyz syntax error and dosn't pack 【发布时间】:2017-10-20 10:40:46 【问题描述】:第一次使用 PyInstaller 3.2.1 在 Windows 10 上打包用 python 3.6.1 编写的 Kivy 1.10.0 应用程序时,请遵循 Kivy.org 应用程序打包教程。当我在 Windows 命令行中打包 .spec
文件时,我收到与 pzy
变量相关的语法错误。我查看了 Kivy 支持部分和 PyInstaller 支持页面,并使用***而不是 Pycharm 重新安装了 PyInstaller 和 Kivy。我收到的错误消息来自 windows 命令行如下:
92 INFO: PyInstaller: 3.2.1
92 INFO: Python: 3.6.1
93 INFO: Platform: Windows-10-10.0.14393-SP0
95 INFO: UPX is not available.
Traceback (most recent call last):
File "C:\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\python36\lib\site-packages\PyInstaller\__main__.py", line 97, in <module>
run()
File "C:\python36\lib\site-packages\PyInstaller\__main__.py", line 90, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\python36\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\python36\lib\site-packages\PyInstaller\building\build_main.py", line 788, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\python36\lib\site-packages\PyInstaller\building\build_main.py", line 734, in build
exec(text, spec_namespace)
File "<string>", line 20
pyz = PYZ(a.pure, a.zipped_data,
^
SyntaxError: invalid syntax
我一直在使用的.spec
文件如下:
# -*- mode: python -*-
from kivy.tools.packaging.pyinstaller_hooks import get_deps_minimal, get_deps_all, hookspath, runtime_hooks
from kivy.deps import sdl2, glew
block_cipher = None
a = Analysis(['KivyCalculator\\main.py'],
pathex=['C:\\Users\\lukeb\\OneDrive\\Documents\\Python\\'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=hookspath(),
runtime_hooks=runtime_hooks(),
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher
**get_deps_all()
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='KivyCalculator',
debug=False,
strip=False,
upx=True,
console=True , icon='KivyCalculator\\icon.ico')
coll = COLLECT(exe,Tree('C:\\Users\\lukeb\\OneDrive\\Documents\\Python\\KivyCalculator'),
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=True,
name='KivyCalculator')
如果有人能提供任何帮助,我将不胜感激。
【问题讨论】:
【参考方案1】:这是因为您在 .spec
文件中输入了一个错字,而该文件只是 Python,所以您基本上会得到这样的结果:
a = Analysis(...,
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher # no comma
**get_deps_all() # no closing bracket
pyz = PYZ(a.pure, a.zipped_data, # bam, syntax error
cipher=block_cipher)
【讨论】:
以上是关于PyInstaller 3.2.1 与 Kivy 1.10.0 pyz 语法错误并且不打包的主要内容,如果未能解决你的问题,请参考以下文章
Pyinstaller 难以通过 Kivy 构建 FileChooserListView
如何从我的 kivy 应用程序(Pyinstaller)获取 Windows 可执行文件?
使用 pyinstaller 打包后 Kivy 应用程序崩溃