我是Python的新手,我正在运行Python 3.6。尝试使用cx_freeze和下面的代码在名为“setup.py”的文件中构建可执行文件。我把程序的python脚本和图标文件放在python主目录文件夹中。当我在命令提示符下键入“python setup.py build”时,它会显示“正在运行构建”,然后立即生成一个新的命令提示符。没有给出错误,但之后我无法在任何地方找到exe。我究竟做错了什么?我是在错误的地方搜索exe文件,还是构建失败而没有给出错误消息?
import cx_Freezefrom cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = ["numpy","tkinter"], excludes = [],includes = ["numpy","tkinter"],
include_files = ["battleship.ico"])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('battleship.py', base=base)
]
setup(
name='Battleship',
version = '1.0',
description = 'A PvC Battleship Game',
options = dict(build_exe = buildOptions),
executables = executables
)
答案 0 :(得分:-1)
使用py2exe时 试试这个
import sys
try:
import py2exe
except:
raw_input('Please install py2exe first...')
sys.exit(-1)
from distutils.core import setup
import shutil
sys.argv.append('py2exe')
setup(
options={
'py2exe': {'bundle_files': 1, 'compressed': True }
},
console=[
{'script': "script.py"}
],
zipfile=None,
)
注意:用你的python脚本重新"script.py"
并像这样运行这个脚本
python exe.py