首页 > 解决方案 > 什么导致IndexError:py2exe中的元组索引超出范围

问题描述

我刚刚安装了 Python 3.8.5 和 py2exe 0.9.2.2。我有一个 setup.py 可以在 Python 2.7 上与 py2exe 0.6.9 一起使用。当我使用新版本运行 setup.py py2exe(实际命令行是 py setupexe.py py2exe)时,我得到:

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

setup.py:

from distutils.core import setup
import py2exe
from md2html import __VERSION__
setup(name='md2html',
      version=__VERSION__,
      author='xxxxx',
      author_email='xxxxx',
      description='Convert Markdown to HTML',
      requires=['markdown(>=2.6.6)'],
      console=['md2html.py'],
      options={"py2exe":{
          "excludes": [
              'pyreadline', 'difflib', 'doctest', 'optparse', 'pickle', 'calendar', 'email', 'ftplib', 'httplib', 'rfc822', 'socket', 'select', 'ssl', '_ssl']  # Exclude standard library
               }}
)

正如我所说,这以前有效。我的下一步是在 pdb 中运行它,但在我跳入不熟悉的代码之前,我想我会问。在 Windows 10 上运行。谢谢。更新:这个问题产生了类似的错误。答案是 py2exe 不适用于 Python 3.4 之后的版本。令人失望!它建议pyinstaller,我将对其进行调查。我真的希望有办法让 py2exe 工作。

标签: pythonpython-3.xpy2exe

解决方案


推荐阅读