美文网首页python
Python 程序打包工具:py2exe 和 PyInstall

Python 程序打包工具:py2exe 和 PyInstall

作者: ef6f9c30080a | 来源:发表于2019-06-24 08:03 被阅读104次

    通常执行 python 程序要有相应的 Python 环境,但某些特定场景下,我们可能并不愿意这么麻烦的去配置这些环境(比如将写好的脚本发给客户进行操作),如果可以提前将程序打包成 Windows平台的 .exe 文件或者是Linux下的 .sh 脚本,那么使用起来就会方便很多,py2exe 和 PyInstaller 这两款工具都是干这么个事的,下面以 hello.py 脚本(代码内容如下)为例进行介绍。

        age = input("How old are you?\n")
        print("A: " + age)
    

    提示:PyInstaller 可以在 Windows 和 Linux 下使用,更推荐使用,而 py2exe 暂不支持 Linux 平台

    PyInstaller

    1. 安装

    pip install pyinstaller

    1. 使用
    PyInstaller

    常见的用法有:

    • 生成单个可执行文件:pyinstaller -F hello.py
    • 生成指定icon的可执行文件:pyinstaller -i xxx.ico hello.py

    在当前目录下的 dist 文件夹内可以找到生成后的可执行文件(脚本),更多用法请参考说明

    py2exe

    1. 安装

    pip install py2exe

    1. 使用
    py2exe build error

    如上图,打包失败了,留意到这里说不支持 python3.6,果断放弃,有兴趣的可以自行降低到 python3.4 或 python3.5 进行尝试。

    文章已授权获得转载,原文地址:https://blog.mariojd.cn/build-python-program-with-py2exe-or-pyinstaller.html

    相关文章

      网友评论

        本文标题:Python 程序打包工具:py2exe 和 PyInstall

        本文链接:https://www.haomeiwen.com/subject/lxwiqctx.html