如何确定主机系统使用的LIBC实现

发布于 2025-01-29 12:54:21 字数 387 浏览 1 评论 0原文

在使用预构建的二进制文件和绑定生成器的Python设置代码中,我们检查操作系统和CPU架构,并相应地下载二进制文件。

现在,Manlinux(Glibc)和Muslinux(Musl)都有二进制文件。我们如何找出主机系统使用的LIBC实现? 我知道platform.libc_ver(),但是对于Musl主机,它目前只是返回两个空字符串(请参见 cpython问题87414 )。

但是,已经有更精确的代码可用,因为pip需要选择正确的车轮。

In our Python setup code that uses pre-built binaries and a bindings generator, we check the operating system and CPU architecture, and download binaries accordingly.

Now, there are binaries for both manylinux (glibc) and musllinux (musl). How can we find out which libc implementation the host system uses?
I am aware of platform.libc_ver(), but for musl hosts, it currently just returns two empty strings (see CPython issue 87414).

However, there has to be more precise code available already, as pip needs means to choose the right wheel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晨曦慕雪 2025-02-05 12:54:21
from packaging.tags import sys_tags
tags = list(sys_tags())
print('musllinux' in tags[0].platform)
from packaging.tags import sys_tags
tags = list(sys_tags())
print('musllinux' in tags[0].platform)
一杯敬自由 2025-02-05 12:54:21

这是我现在正在使用的解决方案。它是由 @andrewnelson的答案刺激的,还使用了平台模块,但它作为platform.libc_ver()的覆盖作品写入,并直接呼叫到packaging._musllinux

import sys
import platform
import packaging._musllinux

def get_libc_info():
    name, ver = platform.libc_ver()
    if not name:
        musl_ver = packaging._musllinux._get_musl_version(sys.executable)
        if musl_ver:
            name, ver = "musl", f"{musl_ver.major}.{musl_ver.minor}"
    return name, ver

print( get_libc_info() )

This is the solution I am using now. It is insipred by @AndrewNelson's answer and also uses the platform module, but it is written as an overlay for platform.libc_ver() and calls into packaging._musllinux directly.

import sys
import platform
import packaging._musllinux

def get_libc_info():
    name, ver = platform.libc_ver()
    if not name:
        musl_ver = packaging._musllinux._get_musl_version(sys.executable)
        if musl_ver:
            name, ver = "musl", f"{musl_ver.major}.{musl_ver.minor}"
    return name, ver

print( get_libc_info() )
套路撩心 2025-02-05 12:54:21

如果您只是在检查glibc vs musl,为什么不只是:

import platform

def is_musl():
    libc, version = platform.libc_ver()
    return libc != "glibc"

If you are just checking for glibc vs musl, why not just:

import platform

def is_musl():
    libc, version = platform.libc_ver()
    return libc != "glibc"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文