简体   繁体   English

尝试将 Python 脚本编译为 exe 时出错

[英]Error while trying to compile Python script to exe

I'm trying to compile python script to exe.我正在尝试将 python 脚本编译为 exe。 My script - hello.py :我的脚本 - hello.py

print("hello")

My setup.py :我的setup.py

from distutils.core import setup
import py2exe, sys, os


sys.argv.append('py2exe')

setup(
    name = 'hello',
    description = 'hello script',
    version = '1.0',
    
    options = {'py2exe': {'bundle_files': 1, 'compressed': True,'dist_dir': ".",'dll_excludes':['w9xpopen.exe']}},
    console = [{'script': r"hello.py"}],
    zipfile = None,
)

I run:我跑:

py -3 setup.py install

The error:错误:

py -3 setup.py install
running install
running build
running install_egg_info
Removing C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\hello-1.0-py3.7.egg-info
Writing C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\hello-1.0-py3.7.egg-info
running py2exe
Traceback (most recent call last):
  File "setup.py", line 19, in <module>
    zipfile = None,
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
    self._run()
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
    builder.analyze()
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\runtime.py", line 160, in analyze
    self.mf.import_hook(modname)
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
    module = self._gcd_import(name)
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
    return self._find_and_load(name)
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code
    for what, args in self._scan_opcodes(code):
  File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
    yield "store", (names[oparg],)
IndexError: tuple index out of range

Do you know how to resolve this error?你知道如何解决这个错误吗?

py2exe seems to support up to Python 3.4 (thanks Michael Butscher) py2exe 似乎支持 Python 3.4(感谢 Michael Butscher)

However, there are other libraries such as Pyinstaller which work just fine, and are compatible with a variety of Python versions (from Python 2.7 to 3.5+)但是,还有其他库,例如 Pyinstaller 可以正常工作,并且与各种 Python 版本兼容(从 Python 2.7 到 3.5+)

Check it out, it's actually really easy:)看看吧,其实很简单:)

https://pyinstaller.readthedocs.io/en/stable/ https://pyinstaller.readthedocs.io/en/stable/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM