使用PyInstaller 3.2.1在应用程序打包的Kivy.org教程之后第一次在Windows 10上打包用python 3.6.1编写的Kivy 1.10.0应用程序。当我在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')
我非常感谢人们可以提供的任何帮助。
答案 0 :(得分: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)