2

I tried importing the MySQLdb within iPython and received the following error.

ImportError                               Traceback (most recent call last)
<ipython-input-4-f5538763dbdb> in <module>()
----> 1 import MySQLdb as mdb
      2 import sys

/Users/user1/anaconda/lib/python2.7/site-packages/MySQLdb/__init__.py in <module>()
     17 from MySQLdb.release import __version__, version_info, __author__
     18 
---> 19 import _mysql
     20 
     21 if version_info != _mysql.version_info:

ImportError: dlopen(/Users/user1/anaconda/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Users/user1/anaconda/lib/python2.7/site-packages/_mysql.so
  Reason: image not found

I found a few posts on Stackoverflow of a similar nature, where it was suggested that the System Integrity Protection should be disabled, which I have now.

I also edited my bashprofile as suggested for OSX El Capitan in this post, Python mysqldb: Library not loaded: libmysqlclient.18.dylib but I still haven't been able to overcome this issue.

A little more information incase it helps diagnose the issue:

  • Python version: Python 2.7.10 |Anaconda 2.4.0 (x86_64)| (default, Oct 19 2015, 18:31:17) [GCC 4.2.1 (Apple Inc. build 5577)]
  • Result of 'which python' : /Users/user1/anaconda/bin/python
  • MySQL Version installed: mysql-5.7.10
  • MySQL-Python version: MySQL-python-1.2.5

Where am I going wrong?

user2762934
  • 2,332
  • 10
  • 33
  • 39

3 Answers3

5

you can try:

 export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
  • export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ helped for me – Taras Nov 02 '19 at 12:31
  • after trying a number of other suggestions to solve this issue whilst trying to get django to work with mysql on os x, this worked for me as well – A Steinmetz Jan 30 '20 at 05:25
4

After some research, I figured that the issue might have been due to OpenSSL, and permissions related to this in El Capitan. I found two resources which hinted at similar solutions:

  1. https://stackoverflow.com/a/23945292/2762934
  2. https://github.com/phpbrew/phpbrew/issues/607

So here it is:

brew install --upgrade openssl
brew unlink openssl && brew link openssl --force
Community
  • 1
  • 1
user2762934
  • 2,332
  • 10
  • 33
  • 39
0

I had the same problem and tried a few things including the brew install, unlink, link solution without any luck. For OS X 10.12.3 running Python 2.7.12, Anaconda 2.3.0 the following worked for me.

  1. Turn off System Integrity Protection: Reboot the Mac and hold down Command + R, open the terminal and enter: csrutil disable; reboot
  2. After rebooting: cd /usr/local/Cellar/openssl/1.0.2k/lib sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/lib/
Bryan Prazen
  • 323
  • 3
  • 7