Python: MySQLdb and "Library not loaded: libmysqlclient.16.dylib"
Question:
Upon trying to import MySQLdb after installation using PIP on Mac OS X 10.6, the following error occurs:
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
Answer:
The issue arises because libmysqlclient.16.dylib is not found in the default library search path. To resolve this:
Check MySQL Installation Path:
Ensure that MySQL is installed in the expected location, typically under /usr/local/mysql.
Set DYLD_LIBRARY_PATH:
After installation, export the DYLD_LIBRARY_PATH environment variable to include the MySQL library path:
<code class="bash">export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/</code>
Restart Python:
Restart Python to load the updated environment variable. This should allow MySQLdb to be imported successfully.
Additional Notes:
The above is the detailed content of How to Fix the \'Library not loaded: libmysqlclient.16.dylib\' ImportError When Using MySQLdb on Mac OS X 10.6?. For more information, please follow other related articles on the PHP Chinese website!