Pyinstaller Kivy app ValueError:没有足够的值来解包(期望3个,得到2个)



所以基本上我一直在用Kivy做一个应用程序,现在我想用pyinstaller把它编译成一个可执行文件。我遵循了官方的kivy指南和pyinstaller规范文件文档中的步骤(虽然没有那么多),当我尝试运行我的规范文件时,下面是在终端上打印的内容:

C:UsersHPDesktopTPM-Kivy>pyinstaller TPManager.spec
9680 INFO: PyInstaller: 4.3
9680 INFO: Python: 3.9.6
9968 INFO: Platform: Windows-10-10.0.19042-SP0
10063 INFO: UPX is not available.
12270 INFO: Extending PYTHONPATH with paths
['C:\Users\HP\Desktop\TPM-Kivy', 'C:\Users\HP\Desktop\TPM-Kivy']
64392 INFO: checking Analysis
138561 INFO: checking PYZ
139010 INFO: checking Tree
161817 INFO: checking Tree
162301 INFO: checking Tree
Traceback (most recent call last):
162502 WARNING: stderr: Traceback (most recent call last):
File "c:python39librunpy.py", line 197, in _run_module_as_main
162848 WARNING: stderr:   File "c:python39librunpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
163351 WARNING: stderr:     return _run_code(code, main_globals, None,
File "c:python39librunpy.py", line 87, in _run_code
163351 WARNING: stderr:   File "c:python39librunpy.py", line 87, in _run_code
exec(code, run_globals)
163353 WARNING: stderr:     exec(code, run_globals)
File "C:Python39Scriptspyinstaller.exe__main__.py", line 7, in <module>
163354 WARNING: stderr:   File "C:Python39Scriptspyinstaller.exe__main__.py", line 7, in <module>
File "c:python39libsite-packagesPyInstaller__main__.py", line 114, in run
163355 WARNING: stderr:   File "c:python39libsite-packagesPyInstaller__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
163600 WARNING: stderr:     run_build(pyi_config, spec_file, **vars(args))
File "c:python39libsite-packagesPyInstaller__main__.py", line 65, in run_build
163721 WARNING: stderr:   File "c:python39libsite-packagesPyInstaller__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
163723 WARNING: stderr:     PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:python39libsite-packagesPyInstallerbuildingbuild_main.py", line 737, in main
163724 WARNING: stderr:   File "c:python39libsite-packagesPyInstallerbuildingbuild_main.py", line 737, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
163822 WARNING: stderr:     build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:python39libsite-packagesPyInstallerbuildingbuild_main.py", line 684, in build
163825 WARNING: stderr:   File "c:python39libsite-packagesPyInstallerbuildingbuild_main.py", line 684, in build
exec(code, spec_namespace)
163827 WARNING: stderr:     exec(code, spec_namespace)
File "TPManager.spec", line 27, in <module>
163829 WARNING: stderr:   File "TPManager.spec", line 27, in <module>
exe = EXE(pyz, Tree('C:\Users\HP\Desktop\TPM-Kivy'),
163830 WARNING: stderr:     exe = EXE(pyz, Tree('C:\Users\HP\Desktop\TPM-Kivy'),
File "c:python39libsite-packagesPyInstallerbuildingapi.py", line 402, in __init__
163831 WARNING: stderr:   File "c:python39libsite-packagesPyInstallerbuildingapi.py", line 402, in __init__
self.toc.extend(arg)
164157 WARNING: stderr:     self.toc.extend(arg)
File "c:python39libsite-packagesPyInstallerbuildingdatastruct.py", line 103, in extend
164158 WARNING: stderr:   File "c:python39libsite-packagesPyInstallerbuildingdatastruct.py", line 103, in extend
self.append(entry)
164246 WARNING: stderr:     self.append(entry)
File "c:python39libsite-packagesPyInstallerbuildingdatastruct.py", line 73, in append
164247 WARNING: stderr:   File "c:python39libsite-packagesPyInstallerbuildingdatastruct.py", line 73, in append
unique = unique_name(entry)
164248 WARNING: stderr:     unique = unique_name(entry)
File "c:python39libsite-packagesPyInstallerbuildingdatastruct.py", line 35, in unique_name
164250 WARNING: stderr:   File "c:python39libsite-packagesPyInstallerbuildingdatastruct.py", line 35, in unique_name
name, path, typecode = entry
164252 WARNING: stderr:     name, path, typecode = entry
ValueError: not enough values to unpack (expected 3, got 2)
164253 WARNING: stderr: ValueError: not enough values to unpack (expected 3, got 2)

我完全不知道为什么会这样,所以我在这里。有人知道这个错误背后的原因和解决方案吗?任何帮助将不胜感激!

这是我的规范文件:

TPManager.spec

from kivy_deps import sdl2, glew
# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

a = Analysis(['main.py'],
pathex=['C:\Users\HP\Desktop\TPM-Kivy'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
a.datas += [('./main.kv', '.')]
a.datas += [('./Resources', 'Resources')]
exe = EXE(pyz, Tree('C:\Users\HP\Desktop\TPM-Kivy'),
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
name='TPManager',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True , icon='GUIIcon.ico')

好吧,我设法解决了我自己的问题,所以对于任何人谁来到这里之后,问题是与.spec文件(或至少在我的情况下)在这一行:

a.datas += [('./main.kv', '.')]
a.datas += [('./Resources', 'Resources')]

这里的解决方案实际上是将您的数据放在Analysis类的datas变量中,而不是稍后添加它们,像这样:

from kivy_deps import sdl2, glew
# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

a = Analysis(['main.py'],
pathex=['C:\Users\HP\Desktop\TPM-Kivy'],
binaries=[],
#put your data here instead of adding it in later
datas=[('./main.kv', '.'), ('./Resources', 'Resources')], 
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz, Tree('C:\Users\HP\Desktop\TPM-Kivy'),
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
name='TPManager',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True , icon='GUIIcon.ico')

相关内容

最新更新