MacOS Big Sur - Python ctypes find_library does not find libraries (ssl, CoreFoundation, etc

Viewed 7797

MacOS Big Sur is out in Dev Beta and I am running it to test out a few things. One of the things I've noticed is that in Python ctypes, find_library() no longer finds the libraries.

An example would be

from ctypes.util import find_library

find_library("ssl")

This should find the ssl file similar to the output like

>>> find_library("ssl")
'libssl.so.1.1'

However, with Big Sur, it finds nothing. I noticed their are some Dynamic Linker changes. That might contribute to this behavior.

Has anyone else encountered this? I am looking for the new method for finding libraries across the Big Sur system.

I believe it is the same as iOS in that it's using /System/Library/dyld/dyld_shared_cache_x86_64 for shared cache. But I am not familiar enough to know how to open that file for accessing things like CoreFoundations, ssl, etc. Still looking into it.

3 Answers

This issue is due to python using stat() to check for dylibs on disk before it dlopen's them. This behaviour stopped working in macOS Big Sur due to dylibs being removed from disk when they are included in the dyld shared cache.

The python included in macOS has a fix for this.

/usr/bin/python3
from ctypes.util import find_library
>>> find_library("ssl")
'libssl.so.1.1'

Additionally, here is a link to a pull request for open source python for the same fix there. https://github.com/python/cpython/pull/21241

I ended up using static paths for my purpose.

You should generally consider that as of Python 3.9.0, 3.8.6, 3.7.9 MacOS 11 or Apple Silicon aren't supported. Track the progress here: https://bugs.python.org/issue41100

Related