Vineeth Sai
Vineeth Sai

Reputation: 3455

Django MySQL throws an error, Library not loaded: /usr/local/opt/[email protected]/lib/libmysqlclient.18.dylib When I upgraded from 5.6 to 5.7 mysql

Yes, this seems like a common error. But something else is wrong with my environment. I have upgraded from MySQL 5.6 version to 5.7.

I can access mysql5.7 by typing mysql into the console.

I have updated the DYLD_LIBRARY_PATH to reflect new 5.7 location

git:(parent-child) ✗ echo $DYLD_LIBRARY_PATH
/usr/local/opt/[email protected]/lib/:

But the error for reason still says it is trying to load from 5.6 version.

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Users/vineeth/envs/automize2.0/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
    import MySQLdb as Database
  File "/Users/vineeth/envs/automize2.0/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
    from . import _mysql
ImportError: dlopen(/Users/vineeth/envs/automize2.0/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/[email protected]/lib/libmysqlclient.18.dylib
  Referenced from: /Users/vineeth/envs/automize2.0/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
  Reason: image not found

Notice the error says it still is trying locate /usr/local/opt/[email protected]/lib/libmysqlclient.18.dylib

I have reinstalled almost everything since this error came.

Tried several solutions

Python mysqldb: Library not loaded: libmysqlclient.18.dylib

rails + MySQL on OSX: Library not loaded: libmysqlclient.18.dylib

Nothing seems to change its reference.

How do I make it refer to the newer one which is in /usr/local/opt/[email protected]/lib/

Also reinstalled mysqlclient with pip but still no luck.

Help is welcome. Been struggling since a day.

Upvotes: 0

Views: 154

Answers (1)

AKX
AKX

Reputation: 169338

To expand my comment as an answer:

Pip compiles source packages into wheels that get cached into your local Pip cache. However, it has no knowledge of the "ambient" dependencies that may affect how the binary package gets compiled, in this case the MySQL shared library.

Recreating the virtualenv won't directly help, since Pip will use the cached binary wheel (to save you from a recompilation).

You could:

Upvotes: 1

Related Questions