In an attempt to establish a development environment for Python/Django on macOS X 10.6, MySQL was installed from the provided DMG and MySQL-python was installed using pip.
Upon attempting to import MySQLdb, the following error was encountered:
Traceback (most recent call last): File "<string>", line 1, in <module> File "/Library/Python/2.6/site-packages/MySQLdb/__init__.py", line 19, in <module> import _mysql ImportError: dlopen(/Library/Python/2.6/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib Referenced from: /Library/Python/2.6/site-packages/_mysql.so Reason: image not found
To address this issue, it is necessary to set the DYLD_LIBRARY_PATH environment variable after installing MySQL-python:
<code class="Bash">export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/</code>
This variable should be set to the directory containing the MySQL libraries, which is typically /usr/local/mysql/lib/.
The above is the detailed content of How to Fix \"Library not loaded: libmysqlclient.16.dylib\" Error When Using MySQLdb in Python on macOS?. For more information, please follow other related articles on the PHP Chinese website!