【问题标题】:Pyinstaller Kivy app ValueError: not enough values to unpack (expected 3, got 2)Pyinstaller Kivy app ValueError: no enough values to unpack (expected 3, got 2)
【发布时间】:2021-09-07 05:50:43
【问题描述】:

所以基本上我一直在使用 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')

【问题讨论】:

  • 我怀疑错误来自Tree('C:\\Users\\HP\\Desktop\\TPM-Kivy')。如果删除那段代码会发生什么?
  • 我尝试删除那个位,不,仍然是同样的错误。无论哪种方式,它仍然是强制性的,以使我的 kivy 应用程序真正工作,至少根据 kivy 文档。不过,感谢您的帮助!
  • 有趣,我从来没有用过。

标签: python kivy pyinstaller


【解决方案1】:

好吧,我设法自己解决了我的问题,所以对于此后来到这里的任何人来说,问题出在这一行中的 .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')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-10
    • 2020-10-26
    • 2017-12-23
    • 2022-11-12
    • 2020-11-19
    • 2022-07-22
    • 2021-12-31
    • 2020-12-16
    相关资源
    最近更新 更多