IndexError:使用py2exe时元组索引超出范围 [英] IndexError: tuple index out of range when using py2exe

查看:86
本文介绍了IndexError:使用py2exe时元组索引超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用 py2exe 制作可执行文件.我使用 Python 3.6.我使用的脚本导入 openpyxlpptx 并且在我使用 Pycharm 或使用命令窗口运行脚本时运行良好.

I'm currently trying to make an executable using py2exe. I use Python 3.6. The script I'm using imports openpyxl and pptx and runs fine when I use Pycharm or run the script using the command window.

输出产生错误:

IndexError: tuple index out of range

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

Below you can find the cmd output:

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'])

推荐答案

更新 (2020-11-17): py2exe LIVES!!!

显然,我一年前的悲观情绪(见原帖底部的更新")是没有根据的.py2exe 于 2020 年 10 月和 11 月发布了新版本,在 0.10.0.2 中支持 3.5-3.8,并在 0.10.1.0 中增加了 3.9 支持(删除支持 3.4 及更早版本).只要您升级到合适的py2exe 版本(0.10 及更高版本),就不会出现此问题.

Update (2020-11-17): py2exe LIVES!!!

Apparently my pessimism a year ago (see "Update" at bottom of original post) was unwarranted. py2exe released new versions in October and November of 2020, supporting 3.5-3.8 in 0.10.0.2 and adding 3.9 support in 0.10.1.0 (dropping support for 3.4 and earlier). As long as you upgrade to an appropriate py2exe version (0.10 and higher), this problem should not occur.

Python 3.6 完全重新设计了 CPython 的字节码(它不再是字节"代码,而是字代码,其中所有操作码的宽度都是两个字节,而不是 1-3 个字节).

Python 3.6 completely redesigned the bytecode for CPython (it's not a "byte" code at all anymore, it's a wordcode, where all opcodes are two bytes wide instead of 1-3).

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

The failure you're seeing occurs in py2exe opcode parsing code, which, given the most recent posted version of py2exe only claims support for 3.3 and 3.4, could not possibly have knowledge of, or support for, the new wordcode opcodes; they hadn't even been conceived of at the time py2exe was last updated. The bytecode often changes in small ways from version to version that could break even Python 3.5 (given only 3.3 and 3.4 support is claimed explicitly), but 3.6 is 100% guaranteed to fail.

更新:此时(2019 年 11 月),距上次 py2exe 发布,到 2020 年初(当 Python 2 支持完全失效时),它将无法在任何支持的 Python 版本上运行(3.4 已经超出支持).我认为可以肯定地说该项目已被放弃;找到其他选项,例如cx_FreezePyInstaller.

Update: At this point (November 2019), it's been over five years since the last py2exe release, and by the beginning of 2020 (when Python 2 support lapses completely), it will not run on any supported version of Python (3.4 is already out of support). I think it's safe to say the project is abandoned; find other options, e.g. cx_Freeze or PyInstaller.

这篇关于IndexError:使用py2exe时元组索引超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆