问题
这个问题主要是在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 packagerun_pyinstaller()File "D:\1\Python310\lib\site-packages\PyInstaller\__main__.py", line 198, in runrun_build(pyi_config, spec_file, **vars(args))File "D:\1\Python310\lib\site-packages\PyInstaller\__main__.py", line 69, in run_buildPyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 1069, in mainbuild(specfile, distpath, workpath, clean_build)File "D:\1\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 1009, in buildexec(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 assemblepriority_scripts.append(self.graph.add_script(script))File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 268, in add_scriptself._top_script_node = super().add_script(pathname)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1260, in add_scriptself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1332, in import_hooktarget_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_packagetarget_package = self._safe_import_module(File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hookself.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1371, in import_hookfor 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_submodulessubmodule = self._safe_import_module(File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_moduleself._process_imports(n)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2703, in _process_importstarget_modules = self._safe_import_hook(*import_info, **kwargs)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hookreturn 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_hooktarget_modules = self.import_hook(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in import_hooksubmodule = self._safe_import_module(head, mname, submodule)File "D:\1\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 484, in _safe_import_modulereturn 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_modulen = self._scan_code(module, co, co_ast)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2498, in _scan_codeself._scan_bytecode(File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2602, in _scan_bytecodefor inst in util.iterate_instructions(module_code_object):File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\util.py", line 44, in iterate_instructionsyield from iterate_instructions(constant)File "D:\1\Python310\lib\site-packages\PyInstaller\lib\modulegraph\util.py", line 36, in iterate_instructionsyield 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_bytesargval, argrepr = _get_const_info(arg, constants)File "D:\1\Python310\lib\dis.py", line 292, in _get_const_infoargval = const_list[const_index]
IndexError: tuple index out of range
解决方案
找到 /Lib/dis.py文件
找到def _unpack_opargs(code)函数,在else语句中添加extended_arg=0,如下:
保存即可