问题
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?
回答1:
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:
- https://stackoverflow.com/a/23945292/2762934
- https://github.com/phpbrew/phpbrew/issues/607
So here it is:
brew install --upgrade openssl
brew unlink openssl && brew link openssl --force
回答2:
you can try:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
回答3:
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.
- Turn off System Integrity Protection: Reboot the Mac and hold down Command + R, open the terminal and enter: csrutil disable; reboot
- 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/
来源:https://stackoverflow.com/questions/34956124/error-with-mysqldb-on-os-x-el-capitan