Skip to main content
 首页 » 编程设计

Python to EXE 构建一个空文件

2025年04月02日14落叶无声

我用了cx_Freeze将我的 Python 应用程序转换为 Windows 的模块。

我有一个简单的 Python 文件 norm.py :

print("Hi there !") 

另一个文件makeup.py将上面的转换成exe:

import sys 
from cx_Freeze import setup, Executable 
 
include_files = ['autorun.inf'] 
os_base = None 
 
if sys.platform == "win32": 
    os_base = "Win32GUI" 
 
setup(name="puzzle", 
        version="0.1", 
        description="Very cool puzzle", 
        options={'build_exe':{'include_files':include_files}}, 
        executables=[Executable("norm.py", base=os_base)]) 

我在同一文件夹中还有 autorun.inf。 当我通过运行命令构建它时也没有出现错误:

python makeup.py build 

它创建了一个 build 文件夹,里面有 norm.exe 。当我通过我的终端运行这个 exe 时,它​​什么也没做。我期待它打印 "Hi there!"

我正在使用 Python 3.4,因为一些帖子说 3.5 这个模块有问题。

请您参考如下方法:

您正在使用

创建一个 GUI 应用程序
if sys.platform == "win32": 
    os_base = "Win32GUI" 

您应该删除它,以便构建控制台应用程序。