我目前正在尝试使用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'])
Storybookmaker.py
文件是否位于与同一目录中setup.py
?您可以尝试setup(console=[os.path.join(os.path.dirname(__file__,'Storybookmaker.py')])
确保找到该文件。
setup.py
文件吗?因为问题出在那儿,而不是在那儿py2exe
工作正常。