Pyinstaller Kivy app ValueError: not enough values to unpack (expected 3, got 2)

Pyinstaller Kivy app ValueError: not enough values to unpack (expected 3, got 2)

所以基本上我一直在用 Kivy 制作一个应用程序,现在我想使用 pyinstaller 将它编译成一个可执行文件。我按照 official kivy guide 和 pyinstaller 规范文件文档中的步骤进行操作(虽然没有那么多),当我尝试 运行 我的规范文件时,这是终端中打印的内容:

C:\Users\HP\Desktop\TPM-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:\python39\lib\runpy.py", line 197, in _run_module_as_main
162848 WARNING: stderr:   File "c:\python39\lib\runpy.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:\python39\lib\runpy.py", line 87, in _run_code
163351 WARNING: stderr:   File "c:\python39\lib\runpy.py", line 87, in _run_code
     exec(code, run_globals)
163353 WARNING: stderr:     exec(code, run_globals)
   File "C:\Python39\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
163354 WARNING: stderr:   File "C:\Python39\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
   File "c:\python39\lib\site-packages\PyInstaller\__main__.py", line 114, in run
163355 WARNING: stderr:   File "c:\python39\lib\site-packages\PyInstaller\__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:\python39\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
163721 WARNING: stderr:   File "c:\python39\lib\site-packages\PyInstaller\__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:\python39\lib\site-packages\PyInstaller\building\build_main.py", line 737, in main
163724 WARNING: stderr:   File "c:\python39\lib\site-packages\PyInstaller\building\build_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:\python39\lib\site-packages\PyInstaller\building\build_main.py", line 684, in build
163825 WARNING: stderr:   File "c:\python39\lib\site-packages\PyInstaller\building\build_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:\python39\lib\site-packages\PyInstaller\building\api.py", line 402, in __init__
163831 WARNING: stderr:   File "c:\python39\lib\site-packages\PyInstaller\building\api.py", line 402, in __init__
     self.toc.extend(arg)
164157 WARNING: stderr:     self.toc.extend(arg)
   File "c:\python39\lib\site-packages\PyInstaller\building\datastruct.py", line 103, in extend
164158 WARNING: stderr:   File "c:\python39\lib\site-packages\PyInstaller\building\datastruct.py", line 103, in extend
     self.append(entry)
164246 WARNING: stderr:     self.append(entry)
   File "c:\python39\lib\site-packages\PyInstaller\building\datastruct.py", line 73, in append
164247 WARNING: stderr:   File "c:\python39\lib\site-packages\PyInstaller\building\datastruct.py", line 73, in append
     unique = unique_name(entry)
164248 WARNING: stderr:     unique = unique_name(entry)
   File "c:\python39\lib\site-packages\PyInstaller\building\datastruct.py", line 35, in unique_name
164250 WARNING: stderr:   File "c:\python39\lib\site-packages\PyInstaller\building\datastruct.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 class 中的 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')