2017-06-23 50 views
0

我是Python的新手,我正在运行Python 3.6。尝试使用cx_freeze和下面的代码在名为“setup.py”的文件中构建可执行文件。我把程序的python脚本和图标文件放在python主目录文件夹中。当我在命令提示符中输入“python setup.py build”时,它会显示“正在运行构建”,然后立即生成新的命令提示符。没有错误,但之后我无法找到任何exe文件。我究竟做错了什么?我是否在错误的地方搜索exe文件,或者在没有提供错误信息的情况下编译失败?使用cx_freeze找不到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

仅供参考,我看到第一行是不正确,但用“从cx_Freeze导入安装程序,可执行文件”替换该行会产生相同的结果。 – SethBorgo

回答

0

当您使用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, 
) 

注:remplace "script.py"与Python脚本并运行该脚本这样

python exe.py