问题
这个问题主要是在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,如下:
保存即可