Mac OS 12 下 Python 报错: dlsym(RTLD_DEFAULT, AbsoluteToNanoseconds): symbol not found

运行celery程序时,出现错误:

10:15:05 worker.1 | Traceback (most recent call last):
10:15:05 worker.1 |   File "/usr/local/bin/celery", line 5, in <module>
10:15:05 worker.1 |     from celery.__main__ import main
10:15:05 worker.1 |   File "/usr/local/lib/python2.7/site-packages/celery/__init__.py", line 133, in <module>
10:15:05 worker.1 |     from celery import five  # noqa
10:15:05 worker.1 |   File "/usr/local/lib/python2.7/site-packages/celery/five.py", line 20, in <module>
10:15:05 worker.1 |     from kombu.five import monotonic
10:15:05 worker.1 |   File "/usr/local/lib/python2.7/site-packages/kombu/five.py", line 56, in <module>
10:15:05 worker.1 |     absolute_to_nanoseconds = CoreServices.AbsoluteToNanoseconds
10:15:05 worker.1 |   File "/usr/local/Cellar/python@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 379, in __getattr__
10:15:05 worker.1 |     func = self.__getitem__(name)
10:15:05 worker.1 |   File "/usr/local/Cellar/python@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 384, in __getitem__
10:15:05 worker.1 |     func = self._FuncPtr((name_or_ordinal, self))
10:15:05 worker.1 | AttributeError: dlsym(RTLD_DEFAULT, AbsoluteToNanoseconds): symbol not found

修改<path to your Python 2 installation>/lib/python2.7/ctypes/util.py文件。

找到if os.name == "posix" and sys.platform == "darwin"

if os.name == "posix" and sys.platform == "darwin":
    from ctypes.macholib.dyld import dyld_find as _dyld_find
    def find_library(name):
        if name == 'CoreServices':
            return '/System/Library/Frameworks/CoreServices.framework/CoreServices'
        elif name == 'libSystem.dylib':
            return '/usr/lib/libSystem.dylib'

修改为如下:

if os.name == "posix" and sys.platform == "darwin":
    from ctypes.macholib.dyld import dyld_find as _dyld_find
    def find_library(name):
        if name == 'CoreServices':
            return '/System/Library/Frameworks/CoreServices.framework/CoreServices'
        elif name == 'libSystem.dylib':
            return '/usr/lib/libSystem.dylib'

        possible = ['@executable_path/../lib/lib%s.dylib' % name,
                    'lib%s.dylib' % name,
                    '%s.dylib' % name,
                    '%s.framework/%s' % (name, name)]
        for name in possible:
            try:
                return _dyld_find(name)
            except ValueError:
                continue
        return None