【以解决】Pyinstaller打包报错IndexError: tuple index out of range

问题

这个问题主要是在Python3.7以上的版本中遇到,用pyinstaller打包的时候发现报错

(pyinstallerEnv) D:\virtualEnv\pyinstallerEnv\Scripts>auto-py-to-exe
pygame 2.5.2 (SDL 2.28.3, Python 3.10.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
12210 ERROR: An error occurred while packaging
Traceback (most recent call last):
  File "D:\1\Python310\lib\site-packages\auto_py_to_exe\packaging.py", line 132, in package
    run_pyinstaller()
  File "D:\1\Python310\lib\site-packages\PyInstaller\__main__.py", line 198, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "D:\1\Python310\lib\site-packages\PyInstaller\__main__.py", line 69, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 1069, in main
    build(specfile, distpath, workpath, clean_build)
  File "D:\1\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 1009, in build
    exec(code, spec_namespace)
  File "C:\Users\admin\AppData\Local\Temp\tmp4_2ywen0\enjoytraderSpider隧道请求代理版本-多进程.spec", line 4, in <module>
    a = Analysis(
  File "D:\1\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 470, in __init__
    self.__postinit__()
  File "D:\1\Python310\lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__
    self.assemble()
  File "D:\1\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 608, in assemble
    priority_scripts.append(self.graph.add_script(script))
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 268, in add_script
    self._top_script_node = super().add_script(pathname)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1260, in add_script
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1332, in import_hook
    target_package, target_module_partname = self._find_head_package(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1511, in _find_head_package
    target_package = self._safe_import_module(
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2369, in _safe_import_hook
    self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1371, in import_hook
    for target_submodule in self._import_importable_package_submodules(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1620, in _import_importable_package_submodules
    submodule = self._safe_import_module(
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1892, in _safe_import_module
    self._process_imports(n)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2160, in _safe_import_hook
    target_modules = self.import_hook(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1891, in _safe_import_module
    n = self._scan_code(module, co, co_ast)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2498, in _scan_code
    self._scan_bytecode(
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2602, in _scan_bytecode
    for inst in util.iterate_instructions(module_code_object):
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\util.py", line 44, in iterate_instructions
    yield from iterate_instructions(constant)
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\util.py", line 36, in iterate_instructions
    yield from (i for i in get_instructions(code_object) if i.opname != "EXTENDED_ARG")
  File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\util.py", line 36, in <genexpr>
    yield from (i for i in get_instructions(code_object) if i.opname != "EXTENDED_ARG")
  File "D:\1\Python310\lib\dis.py", line 338, in _get_instructions_bytes
    argval, argrepr = _get_const_info(arg, constants)
  File "D:\1\Python310\lib\dis.py", line 292, in _get_const_info
    argval = const_list[const_index]
IndexError: tuple index out of range

解决方案

找到 /Lib/dis.py文件
找到def _unpack_opargs(code)函数,在else语句中添加extended_arg=0,如下:
在这里插入图片描述

保存即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西门一刀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值