我正在使用 PyCharm 2016.3.2 + Python 3.6 我安装了 py2exe 来编译我最简单的脚本(使用 pip install py2exe) 安装已成功完成。
所以,我创建了以下 script.py
import os
import winreg
print("Hallo World")
此外,我按照官方网站文档的要求创建了以下 setup.py:setup.py
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options={
'py2exe': {
'compressed': 1,
'optimize': 2,
'bundle_files': 3, # Options 1 & 2 do not work on a 64bit system
'dist_dir': 'dist', # Put .exe in dist/
'xref': False,
'skip_archive': False,
'ascii': False,
}
},
zipfile=None,
console=['script.py'],
)
然后我尝试在 PyCharm 中使用终端窗口和命令运行编译过程: python setup.py py2exe
C:\Users\folder\Script>python setup.py py2exe
running py2exe
Traceback (most recent call last):
File "setup.py", line 36, in <module>
console=['Script.py'],
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\runtime.py", line 158, in analyze
self.mf.import_package(modname[:-2])
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 92, in import_package
self.import_hook(name)
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
self._scan_code(module.__code__, module)
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code
for what, args in self._scan_opcodes(code):
File "C:\Users\folder\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
yield "store", (names[oparg],)
IndexError: tuple index out of range
结果,我得到了多个错误。我做错了什么?请帮我。