简体   繁体   English

MacOS Big Sur - Python ctypes find_library 找不到库(ssl、CoreFoundation 等

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

MacOS Big Sur is out in Dev Beta and I am running it to test out a few things. MacOS Big Sur 已推出 Dev Beta,我正在运行它来测试一些东西。 One of the things I've noticed is that in Python ctypes, find_library() no longer finds the libraries.我注意到的一件事是,在 Python ctypes 中, find_library()不再找到库。

An example would be一个例子是

from ctypes.util import find_library

find_library("ssl")

This should find the ssl file similar to the output like这应该找到类似于 output 的ssl文件

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

However, with Big Sur, it finds nothing.但是,对于 Big Sur,它一无所获。 I noticed their are some Dynamic Linker changes.我注意到他们有一些动态 Linker 变化。 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.我正在寻找在 Big Sur 系统中查找库的新方法。

I believe it is the same as iOS in that it's using /System/Library/dyld/dyld_shared_cache_x86_64 for shared cache.我相信它与 iOS 相同,因为它使用/System/Library/dyld/dyld_shared_cache_x86_64进行共享缓存。 But I am not familiar enough to know how to open that file for accessing things like CoreFoundations, ssl, etc. Still looking into it.但我不够熟悉,不知道如何打开该文件以访问 CoreFoundations、ssl 等内容。仍在研究它。

This issue is due to python using stat() to check for dylibs on disk before it dlopen's them.这个问题是由于 python 在 dlopen 之前使用stat()检查磁盘上的 dylib。 This behaviour stopped working in macOS Big Sur due to dylibs being removed from disk when they are included in the dyld shared cache.由于 dylib 在包含在 dyld 共享缓存中时从磁盘中删除,因此此行为在 macOS Big Sur 中停止工作。

The python included in macOS has a fix for this. macOS 中包含的 python 对此进行了修复。

/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.此外,这里是开源 python 的拉取请求的链接,用于相同的修复。 https://github.com/python/cpython/pull/21241 https://github.com/python/cpython/pull/21241

I ended up using static paths for my purpose.我最终出于我的目的使用了 static 路径。

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.您通常应该考虑到 Python 3.9.0、3.8.6、3.7.9 MacOS 11 或 Apple Silicon 不受支持。 Track the progress here: https://bugs.python.org/issue41100在此处跟踪进度: https://bugs.python.org/issue41100

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM