How to determine which libc implementation the host system uses

Question:

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.

Asked By: mara004

||

Answers:

from packaging.tags import sys_tags
tags = list(sys_tags())
print('musllinux' in tags[0].platform)
Answered By: Andrew Nelson

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"
Answered By: ospider
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.