3

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.

mara004
  • 1,435
  • 11
  • 24

2 Answers2

2
from packaging.tags import sys_tags
tags = list(sys_tags())
print('musllinux' in tags[0].platform)
Andrew Nelson
  • 460
  • 3
  • 11
  • 1
    Interesting. I guess I should take a closer look at packaging. While this doesn't look like the optimal API, I'll want to read packaging's `_musllinux.py` file. I still think a more optimal solution would be if packaging's musl detection code could be moved into the standard library, though. – mara004 Jan 19 '23 at 13:10
  • If you are building wheels, you can use something like `from wheel.vendored.packaging.tags import platform_tags # or sys_tags`. The package `pip` also have this stuff, but `pip` may not exist. – sg qy Mar 28 '23 at 10:30
-1

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"
ospider
  • 9,334
  • 3
  • 46
  • 46
  • that's actually what I'm doing ATM, but it's somewhat unsafe as further libc implementations other than glibc and musl may exist on linux, though uncommon – mara004 Mar 28 '23 at 14:43