首页 文章

Python - IndexError:使用py2exe时元组索引超出范围

提问于
浏览
54

我目前正在尝试使用py2exe创建可执行文件 . 我使用Python 3.6 . 我正在使用的脚本导入openpyxl和pptx,当我使用Pycharm或使用命令窗口运行脚本时运行正常 . 输出产生错误:

IndexError:元组索引超出范围

您可以在下面找到cmd输出:

C:\Python36>python setup.py py2exe
running py2exe
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    setup(console=['Storybookmaker.py'])
  File "C:\Python36\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Python36\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Python36\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python36\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
    self._run()
  File "C:\Python36\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
    builder.analyze()
  File "C:\Python36\lib\site-packages\py2exe\runtime.py", line 160, in analyze
    self.mf.import_hook(modname)
  File "C:\Python36\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
    module = self._gcd_import(name)
  File "C:\Python36\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
    return self._find_and_load(name)
  File "C:\Python36\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:\Python36\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code
    for what, args in self._scan_opcodes(code):
  File "C:\Python36\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
    yield "store", (names[oparg],)
IndexError: tuple index out of range

C:\Python36>

是什么导致IndexError?

编辑:这是 setup.py 文件

from distutils.core import setup
import py2exe

setup(console=['Storybookmaker.py'])

3 回答

  • 44

    Python 3.6 completely redesigned the bytecode for CPython(它是's not a 1354045 code at all anymore, it'是一个字代码,其中所有操作码都是两个字节宽而不是1-3个) .

    您看到的失败发生在 py2exe 操作码解析代码中,鉴于 py2exe 的最新发布版本仅声称支持3.3和3.4,因此无法了解或支持新的字代码操作码;他们甚至在 py2exe 上次更新时都没有想到 . 字节码经常在不同版本之间以小的方式发生变化,甚至可以打破Python 3.5(仅提供3.3和3.4支持),但3.6是100%保证失败 .

  • 6

    我遇到了同样的问题,因为我使用了cx_freeze . 我的应用程序基于wxPython,windows 10,python 3.6,cx_freeze 5.5.1

    这是我使用的安装文件,我在dist文件夹上有msi文件 .

    #setup.py
    import sys, os
    from cx_Freeze import setup, Executable
    
    __version__ = "1.1.0"
    
    include_files = ['logging.ini', 'config.ini', 'running.png']
    excludes = ["tkinter"]
    packages = ["os", "idna", "requests","json","base64","pyodbc"]
    
    setup(
        name = "appname",
        description='App Description',
        version=__version__,
        options = {"build_exe": {
        'packages': packages,
        'include_files': include_files,
        'excludes': excludes,
        'include_msvcr': True,
    }},
    executables = [Executable("b2b_conn.py",base="Win32GUI")]
    )`
    

    那么 python setup.py bdist_msi

  • 5

    Dennis,比你晚了几个小时,我没有运气测试同样的东西,我已经安装了Python 3.6,目前它不起作用 .

    我尝试了一下,我已经安装了Python 3.4.3,并试试这个:

    C:\socket> c:\Python34\python.exe setup.py py2exe
    

    1)输入您的脚本文件夹2)停用您拥有的任何防病毒软件(奇怪的是,通过另一个SO问题知道xD)

    2)通过他的绝对路径调用python 3.4.3解释器,就我而言,我安装在:

    C:\Python34
    

    3)执行命令

    c:\Python34\python.exe setup.py py2exe
    

    希望像我这样的帮助

相关问题