Home > Database > Mysql Tutorial > body text

How to Fix the \'Library not loaded: libmysqlclient.16.dylib\' ImportError When Using MySQLdb on Mac OS X 10.6?

Susan Sarandon
Release: 2024-10-31 03:23:30
Original
706 people have browsed it

How to Fix the

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
Copy after login

Answer:

The issue arises because libmysqlclient.16.dylib is not found in the default library search path. To resolve this:

  1. Check MySQL Installation Path:

    Ensure that MySQL is installed in the expected location, typically under /usr/local/mysql.

  2. 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>
    Copy after login
  3. Restart Python:

    Restart Python to load the updated environment variable. This should allow MySQLdb to be imported successfully.

Additional Notes:

  • If the MySQL installation path is different, adjust the value of DYLD_LIBRARY_PATH accordingly.
  • The library path can be set permanently in /etc/profile or /etc/paths.
  • Ensure that the libmysqlclient.16.dylib file exists in the specified path.

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!