第一个 exe:控制台程序

70.3 第一个 exe:控制台程序

准备 hello.py,在终端进入该文件所在目录,执行 pyinstaller hello.py。

完成后生成 build/(临时)和 dist/(输出),dist/hello/hello.exe 或 dist/hello.exe。

把 exe 复制到其他 Windows 电脑测试(无需装 Python)。

hello.py

# hello.py
print('Hello, 这是打包后的程序!')
input('按回车退出...')

打包命令

# 在 hello.py 所在目录打开终端:
pyinstaller hello.py

# 运行:
# dist\hello\hello.exe   (默认文件夹模式)