V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
huntzhan
V2EX  ›  程序员

利用 PyPI 分发预编译二进制程序(以 redis-server 为例)

  •  2
     
  •   huntzhan ·
    huntzhan · 2020-03-07 16:18:41 +08:00 · 1789 次点击
    这是一个创建于 1482 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在学习 Python 包管理机制,了解到以下信息:

    • PEP-425: Wheel 打包格式支持声明目标部署平台( platform tag ),且 pip install 会根据当前平台信息( i.e. windows/macos/linux )自动选择匹配对应的 wheel。
    • PEP-513PEP-571 定义了一个兼容性较强的 Linux 依赖集合,希望可以接近“一次编译,到处运行”的目标:It would be ideal if wheel packages could be compiled that would work on any linux system. ... we define a standard subset of the kernel+core userspace ABI that, in practice, is compatible enough that packages conforming to this standard will work on many linux systems

    基于此,可以对任意语言实现的源码进行交叉编译,将编译结果打包成 wheel 格式,发布至 PyPI。用户可直接通过 pip 自动下载安装其平台所需的二进制包。

    基于这个思路,我用 GitHub workflow 在 Linux/MacOS 上编译了 Redis 并发布到 PyPI,详见:

    6 条回复    2020-03-12 02:29:14 +08:00
    Buges
        1
    Buges  
       2020-03-07 16:24:12 +08:00 via Android
    非 Python 项目你用 pypi 分发干嘛,有必要吗?
    huntzhan
        2
    huntzhan  
    OP
       2020-03-07 16:28:54 +08:00
    @Buges 不是所有 Python 项目都是用纯 Python 编写的,有的是 Cython (scikit-learn),有的是深度整合 C/C++( pytorch ),还有的甚至是用 Python 套个壳程序主体是其他语言。这种情况就需要考虑交叉编译与分发的选项。
    Buges
        3
    Buges  
       2020-03-07 16:35:59 +08:00 via Android
    @huntzhan 我知道不是纯 Python,Python 包装的上 pypi 当然无可厚非,但其他的没必要套空壳强行打包成 wheel 吧,不同软件都有自己的分发方式。
    huntzhan
        4
    huntzhan  
    OP
       2020-03-07 16:39:59 +08:00
    @Buges 非常同意。我只是提供一个思路,也没有去提倡把任何程序通过 wheel 分发。
    BiuBiuBiu
        5
    BiuBiuBiu  
       2020-03-12 00:54:27 +08:00
    @huntzhan 你好,曾经在 https://www.zhihu.com/question/34039162 这个问题下看到过你关于 SAM 教程的回答,请问能再补一下链接吗?它好像挂了。
    huntzhan
        6
    huntzhan  
    OP
       2020-03-12 02:29:14 +08:00
    @BiuBiuBiu 好周末补下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5761 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 06:23 · PVG 14:23 · LAX 23:23 · JFK 02:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.