# 使用 PyInstaller 将 Python 脚本编译成 exe 文件的示例代码
# 首先需要安装 PyInstaller 库
# 可以通过以下命令安装:
# pip install pyinstaller
# 假设我们有一个简单的 Python 脚本 hello.py,内容如下:
# hello.py
def main():
print("Hello, World!")
if __name__ == "__main__":
main()
# 然后在命令行中使用 PyInstaller 将其编译为 exe 文件:
# 打开命令行工具,导航到 hello.py 所在的目录,然后运行以下命令:
# pyinstaller --onefile hello.py
# 解释说明:
# 1. `--onefile` 参数表示将所有依赖打包成一个单独的 exe 文件。
# 2. 编译完成后,会在 dist 目录下生成一个名为 hello.exe 的文件。
# 3. 运行这个 exe 文件时,它会执行 hello.py 中的代码并输出 "Hello, World!"。
# 如果需要隐藏命令行窗口(适用于 GUI 应用程序),可以添加 `--noconsole` 参数:
# pyinstaller --onefile --noconsole hello.py
上一篇:python url paser
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站