打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Python 程序打包成可执行程序

https://www.toutiao.com/article/7261488155969356347/?log_from=dbc6944c500f6_1691377475968

要将 Python 程序打包成可执行程序,可以使用 PyInstaller 工具。

以下是使用 PyInstaller 的步骤:

  1. 安装 PyInstaller:在命令行中运行以下命令安装 PyInstaller:
pip install pyinstaller
  1. 将脚本打包成可执行文件:在命令行中运行以下命令将 Python 脚本打包成可执行文件:
pyinstaller your_script.py

这将在当前目录下创建一个 dist 文件夹,并在其中生成可执行文件。

  1. 查看可执行文件:在命令行中查看 dist 文件夹中的可执行文件:
ls dist

注意:可执行文件可能会比原始脚本文件大,因为它包含了 Python 解释器和依赖库。

另外,PyInstaller 还提供了许多选项和参数,用于自定义打包过程。

以下是 PyInstaller 的常用选项和参数的例子

  1. 图形化应用程序
pyinstaller window.py --onefile --clean --noconfirm --name window --icon window.ico --distpath .
  1. 命令行程序
pyinstaller cmdline.py --onefile --clean --noconfirm --name cmdline --icon window.ico --distpath .
  1. 带配置的程序
 pyinstaller app.py --add-data "config.xml;config.xml" --add--data "data.ini:data.ini"
  1. 使用构建脚本一次生成多个程序
# build_bin.py

import PyInstaller.__main__

# 图形化应用程序
# pyinstaller window.py --onefile --clean --noconfirm --name window --icon window.ico --distpath .
PyInstaller.__main__.run([
    'window.py',
    '--onefile',
    '--clean',
    '--noconfirm',
    '--windowed',
    '--name=window',
    '--icon=window.ico',
    '--distpath=.'
])

# 命令行程序
# pyinstaller cmdline.py --onefile --clean --noconfirm --name cmdline --icon window.ico --distpath .
PyInstaller.__main__.run([
    'cmdline.py',
    '--onefile',
    '--clean',
    '--noconfirm',
    '--console',
    '--name=cmdline',
    '--icon=cmdline.ico',
    '--distpath=.'
])
python build_bin.py
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
利用PyInstaller将python程序.py转为.exe的方法详解
学会这招真实用!复制粘贴,快速将Python程序打包成exe!
pyinstaller---将py文件打包成exe
pyinstaller安装配置
python文件封装成*.exe文件(单文件和多文件)
手把手教你用wx做一个二维码生成器,并打包成可执行程序
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服