【问题标题】:Python - Package binary, modules and script althogetherPython - 打包二进制文件、模块和脚本
【发布时间】:2014-07-12 20:15:43
【问题描述】:

首先,我仍在学习 Python(它的最佳实践以及整个分发系统的工作原理),所以我不是专家。

我需要创建一个包含特定 Python 二进制文件(比如说 v2.6)、我编写的 Python 脚本及其模块依赖项(2 个模块 -argparseyaml-)的单个包。

我希望将它们全部打包,原因如下:

  • 我将部署脚本的盒子没有相同的 Python 版本(范围从 v2.3x 到 v2.6x)
  • 我不能依赖手动安装 Python 模块,因为它们 并不总是打包在存储库中
  • 如果没有至少一个模块,我就无法编写代码,因为它 需要解析 YAML 文件
  • 我显然无法在所有机器上升级 Python

我尝试了什么:

  • 我使用cx_Freeze 创建了一个包(包含我的脚本+argparseyaml 模块),但是由于使用了一些方法 整个代码不兼容 Python2.3,它拒绝运行
  • 我尝试创建一个自动执行的 Python 鸡蛋,但要么我做到了 出了点问题,或者我遇到了与 cx_Freeze

我希望我不是在要求不可能的事情,但至少,我想对在这样一个异构环境(Python v2.3 到 v2.7)及其依赖项噩梦中开发 Python 脚本有一些反馈。

提前谢谢大家。

问候。

【问题讨论】:

    标签: python binary package python-module


    【解决方案1】:

    听起来你需要 pyinstaller。 * 警告 * -- 我没用过,不过根据docs,超级简单:

    转到脚本的目录(假设它名为 myscript.py)并执行以下命令:(来自上面的文档链接)

    pyinstaller myscript.py

    PyInstaller analyzes myscript.py and:
    
    Writes myscript.spec in the same folder as the script.
    Creates a folder build in the same folder as the script if it does not exist.
    Writes some log files and working files in the build folder.
    Creates a folder dist in the same folder as the script if it does not exist.
    Writes the myscript executable folder in the dist folder.
    

    在 dist 文件夹中,您可以找到分发给用户的捆绑应用程序。

    【讨论】:

    • 感谢您的提示。一个小细节:您似乎需要在具有最低版本的 Python 和 C 库的发行版上构建您的包,否则您将遇到本文中描述的问题:stackoverflow.com/questions/17654363/…
    猜你喜欢
    • 2014-01-07
    • 2020-12-02
    • 2017-05-31
    • 2011-10-01
    • 1970-01-01
    • 2019-10-05
    • 2018-12-01
    • 1970-01-01
    • 2013-11-06
    相关资源
    最近更新 更多