python-3.x - Pyinstaller 和 py2exe 导致错误 : "tuple index out of range"

标签 python-3.x pyinstaller py2exe openpyxl easygui

这是我第一次使用 Pyinstaller,所以请多多包涵。为什么以下会导致错误?我如何解决它。我正在尝试将我编写的 python 程序转换为 windows .exe。

C:\WINDOWS\system32>pyinstaller C:\Users\evank\Desktop\Package\program.py
121 INFO: PyInstaller: 3.2.1
121 INFO: Python: 3.6.1
121 INFO: Platform: Windows-10-10.0.15063-SP0
127 INFO: wrote C:\WINDOWS\system32\program.spec
127 INFO: UPX is not available.
129 INFO: Extending PYTHONPATH with paths
['C:\\Users\\evank\\Desktop\\Package', 'C:\\WINDOWS\\system32']
129 INFO: checking Analysis
131 INFO: Building Analysis because out00-Analysis.toc is non existent
131 INFO: Initializing module dependency graph...
138 INFO: Initializing module graph hooks...
140 INFO: Analyzing base_library.zip ...
Traceback (most recent call last):
  File "C:\Program Files\Python36\Scripts\pyinstaller-script.py", line 11, in <module>
    load_entry_point('PyInstaller==3.2.1', 'console_scripts', 'pyinstaller')()
  File "c:\program files\python36\lib\site-packages\PyInstaller\__main__.py", line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\program files\python36\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\program files\python36\lib\site-packages\PyInstaller\building\build_main.py", line 788, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\program files\python36\lib\site-packages\PyInstaller\building\build_main.py", line 734, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "c:\program files\python36\lib\site-packages\PyInstaller\building\build_main.py", line 212, in __init__
    self.__postinit__()
  File "c:\program files\python36\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in __postinit__
    self.assemble()
  File "c:\program files\python36\lib\site-packages\PyInstaller\building\build_main.py", line 317, in assemble
    excludes=self.excludes, user_hook_dirs=self.hookspath)
  File "c:\program files\python36\lib\site-packages\PyInstaller\depend\analysis.py", line 560, in initialize_modgraph
    graph.import_hook(m)
  File "c:\program files\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1509, in import_hook
    source_package, target_module_partname, level)
  File "c:\program files\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1661, in _find_head_package
    target_module_headname, target_package_name, source_package)
  File "c:\program files\python36\lib\site-packages\PyInstaller\depend\analysis.py", line 209, in _safe_import_module
    module_basename, module_name, parent_package)
  File "c:\program files\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2077, in _safe_import_module
    module_name, file_handle, pathname, metadata)
  File "c:\program files\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2167, in _load_module
    self._scan_code(m, co, co_ast)
  File "c:\program files\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2585, in _scan_code
    module, module_code_object, is_scanning_imports=False)
  File "c:\program files\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2831, in _scan_bytecode
    global_attr_name = get_operation_arg_name()
  File "c:\program files\python36\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2731, in get_operation_arg_name
    return module_code_object.co_names[co_names_index]
IndexError: tuple index out of range

编辑:使用 py2exe 也会导致同样的错误。

请帮助! 谢谢, 埃文克28

最佳答案

好吧,我明白了。 Pyinstaller 尚未为 Python 3.6 做好准备,这是在将 Pyinstaller 与 Python 3.6 一起使用时发生的错误。我卸载了 Pyinstaller 并在命令提示符中使用以下命令安装了 Pyinstaller 的开发版本。

pip uninstall pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/tarball/develop

然后,像往常一样使用 pyinstaller,它就像一个魅力。官方安装还不适用于 Python v3.6。

pyinstaller myprogram.py

关于python-3.x - Pyinstaller 和 py2exe 导致错误 : "tuple index out of range",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45112041/

相关文章:

python - 如何使用 Flask 将二维数组中的表格从 Python 渲染为 HTML?

python - 在单个循环中运行多个测试的最有效方法是什么? Python

python - Pyinstaller: cx_Oracle.InterfaceError: 无法获取 Oracle 环境句柄

python - 如何构建包含cv模块的exe文件

python - py2exe 无法加载指定模块

python - 是否有 Python 3.x 发布生命周期的官方指南?

python - 有没有办法通过只调用类的名称来调用函数?

python - 将 PyInstaller 与 Bokeh 和 CustomJS 结合使用

Python:关于打包应用程序 docker vs pyinstaller 的问题

python - py2exe 打包数据文件