Python – IndexError:使用py2exe时元组索引超出范围
作者:互联网
我目前正在尝试使用py2exe创建可执行文件.我使用Python 3.6.我正在使用的脚本导入openpyxl和pptx,当我使用Pycharm或使用命令窗口运行脚本时运行正常.输出产生错误:
IndexError: tuple index out of range
您可以在下面找到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'])
解决方法:
Python 3.6 completely redesigned the bytecode for CPython(它根本不再是“字节”代码,它是一个字代码,其中所有操作码都是两个字节宽而不是1-3个).
你看到的失败发生在py2exe操作码解析代码中,鉴于py2exe的最新发布版本仅声称支持3.3和3.4,不可能知道或支持新的字代码操作码; py2exe最后一次更新时,他们甚至没有想到它们.字节码经常在不同版本之间以小的方式发生变化,甚至可以打破Python 3.5(只有3.3和3.4支持被明确声明),但3.6是100%保证失败.
标签:py2exe,python 来源: https://codeday.me/bug/20190916/1808087.html