Home > Database > Mysql Tutorial > body text

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

Linda Hamilton
Release: 2024-10-30 15:44:02
Original
221 people have browsed it

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

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

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!

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!