1

I have installed MySQLdb on El Capitan using:

brew install mysql
pip install MySQL-python

When I try python -c "import MySQLdb" I get the following error:

  File "<string>", line 1, in <module>
  File "MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(./_mysql.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Users/<user>/anaconda/lib/python2.7/site-packages/_mysql.so
  Reason: no suitable image found.  Did find:
    /usr/local/bin/mysql/lib/libssl.1.0.0.dylib: stat() failed with errno=20

Found some related posts but still did not figure out how to fix this. Any help is much appreciated.

EDIT: If I decide to revert step 1 (brew uninstall mysql) because SQLite (sqlite3) comes pre-installed with El Capitan, I get the following error message:

  File "<string>", line 1, in <module>
  File "/Users/<user>/anaconda/lib/python2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Users/<user>/anaconda/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
  Referenced from: /Users/<user>/anaconda/lib/python2.7/site-packages/_mysql.so
  Reason: image not found 

What am I missing? Are the two error messages related?

KM.
  • 121
  • 1
  • 8
  • Can you link to the related posts and describe specifically how they didn't help? – darthbith Oct 08 '16 at 14:39
  • @darthbith Have found this post (http://stackoverflow.com/questions/34956124/error-with-mysqldb-on-os-x-el-capitan) but the suggested steps did not help. – KM. Oct 08 '16 at 15:13
  • What do you mean the suggested steps did not help? Did the error message change? What exact steps did you take? Did you try the steps in the post that's linked in that post? The more information and detail you can provide about what you tried, the easier it is to help. – darthbith Oct 08 '16 at 17:28
  • @darthbith I already have openssl-1.0.2j installed so not sure if that post is very relevant after all. I believe the difference lies in the last part of my error message "Did find: ". A possible solution might be to link/"point" it to that location? Is my thinking right? If yes, how do I create this link? Thanks. – KM. Oct 08 '16 at 22:21
  • What about this one: http://stackoverflow.com/questions/28196775/yosemite-python-mysqllib-issue-no-suitable-image-found – darthbith Oct 09 '16 at 01:58
  • I have set the DYLD_LIBRARY_PATH for libmysqlclient, but is there something equivalent to libssl? – KM. Oct 09 '16 at 13:40

1 Answers1

1

I got an error like this after, I assume, homebrew updated mysql. By running pip uninstall mysqlclient && pip install mysqlclient I got things working again without having to set DYLD_LIBRARY_PATH.

Turn
  • 6,656
  • 32
  • 41