# 使用 PyInstaller 将 Python 脚本转换为可执行文件 (exe)
# 首先,确保你已经安装了 PyInstaller。你可以通过以下命令安装它:
# pip install pyinstaller
# 假设我们有一个简单的 Python 脚本 hello.py,内容如下:
"""
hello.py
"""
print("Hello, World!")
# 要将这个脚本转换为 exe 文件,可以在命令行中运行以下命令:
# pyinstaller --onefile hello.py
# 解释:
# - pyinstaller: 调用 PyInstaller 工具。
# - --onefile: 选项表示将所有依赖打包到一个单独的 exe 文件中。
# - hello.py: 要转换的 Python 脚本。
# 运行上述命令后,PyInstaller 会在 dist 目录下生成一个名为 hello.exe 的可执行文件。
# 如果你需要更复杂的设置,比如隐藏终端窗口(适用于 GUI 应用程序),可以使用 --noconsole 选项:
# pyinstaller --onefile --noconsole hello.py
# 注意:在 Windows 上,生成的 exe 文件可以直接运行;而在 macOS 和 Linux 上,生成的是平台特定的可执行文件。
# 示例代码结束
上一篇:python faiss
下一篇:python中assert
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站