The "MySQL" client interface library will not load on MacOS Monterey. The relevant traceback lines are as follows: (System is Django, latest versions of everything.)
ImportError: dlopen(/Users/mike/.virtualenvs/djangoprod/lib/python3.11/site-packages/MySQLdb/_mysql.cpython-311-darwin.so, 0x0002): Library not loaded: '@rpath/libmysqlclient.21.dylib'
Referenced from: '/Users/mike/.virtualenvs/djangoprod/lib/python3.11/site-packages/MySQLdb/_mysql.cpython-311-darwin.so'
Reason: tried: '/usr/lib/libmysqlclient.21.dylib' (no such file)
It seems to me that Python is trying to use @rpath
to find the library, and man dyld
explains to me just what that is. So far, so good ...
I have specified export DYLD_LIBRARY_PATH=/usr/local/mysql-8.0.31-macos12-X86_64/lib
, which is the correct location, but the library is still not being found. (Notice from the tail of line #2 that it appears to be using @rpath
explicitly as part of the library path being searched.) I have read other unrelated forum postings which provide DYLD_LIBRARY_PATH
as a solution, albeit in the Linux environment.
I don't know how to actually see what @rpath
contains.
I do know that "this used to work," but it's been a while since I had anything to do with this application and I frankly don't recall which MacOS version I was using at that time.
Is it possible that "System Integrity Protection" has anything to do with this? I read that in certain cases that it blocks this environment variable, but it is not entirely clear to me when it does and doesn't apply.
The Python3 interpreter in question is located in a "virtual environment" which means that it is actually running out of a user-local directory which therefore would not be covered by SIP. But the libraries themselves do reside in /usr
, which is. I did rebuild that virtual environment.