Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

python - IndexError: tuple index out of range when using py2exe

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.

The output produces the error:

IndexError: tuple index out of range

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:Python36libdistutilscore.py", line 148, in setup
    dist.run_commands()
  File "C:Python36libdistutilsdist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:Python36libdistutilsdist.py", line 974, in run_command
    cmd_obj.run()
  File "C:Python36libsite-packagespy2exedistutils_buildexe.py", line 188, in run
    self._run()
  File "C:Python36libsite-packagespy2exedistutils_buildexe.py", line 267, in _run
    builder.analyze()
  File "C:Python36libsite-packagespy2exe
untime.py", line 160, in analyze
    self.mf.import_hook(modname)
  File "C:Python36libsite-packagespy2exemf3.py", line 120, in import_hook
    module = self._gcd_import(name)
  File "C:Python36libsite-packagespy2exemf3.py", line 274, in _gcd_import
    return self._find_and_load(name)
  File "C:Python36libsite-packagespy2exemf3.py", line 357, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:Python36libsite-packagespy2exemf3.py", line 388, in _scan_code
    for what, args in self._scan_opcodes(code):
  File "C:Python36libsite-packagespy2exemf3.py", line 417, in _scan_opcodes
    yield "store", (names[oparg],)
IndexError: tuple index out of range

C:Python36>

What causes the IndexError?

Edit: here is the setup.py file:

from distutils.core import setup
import py2exe

setup(console=['Storybookmaker.py'])
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


Original Answer before py2exe 0.10 release

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).

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...