0

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/mysql@5.7/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/mysql@5.6/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/mysql@5.6/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/mysql@5.7/lib/

Also reinstalled mysqlclient with pip but still no luck.

Help is welcome. Been struggling since a day.

Vineeth Sai
  • 3,389
  • 7
  • 23
  • 34

1 Answers1

1

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:

AKX
  • 152,115
  • 15
  • 115
  • 172
  • I had no clue that such details are stored inside the cache. I spend almost a day trying to figure out reinstalling stuff, completely oblivious to the fact that this was installing the same stored configurations. Running `pip install --no-cache-dir mysqlclient` fixed the problem. Thank you – Vineeth Sai May 07 '20 at 12:23