Home  >  Article  >  Database  >  How to Fix \"Library not loaded: libmysqlclient.16.dylib\" Error When Using MySQLdb in Python on macOS?

How to Fix \"Library not loaded: libmysqlclient.16.dylib\" Error When Using MySQLdb in Python on macOS?

Linda Hamilton
Linda HamiltonOriginal
2024-10-30 15:44:02221browse

How to Fix

Python: MySQLdb and "Library not loaded: libmysqlclient.16.dylib"

Setup

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.

Issue

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

Resolution

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn