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.
Answers:
from packaging.tags import sys_tags
tags = list(sys_tags())
print('musllinux' in tags[0].platform)
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"
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.
from packaging.tags import sys_tags
tags = list(sys_tags())
print('musllinux' in tags[0].platform)
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"