在Mac OS X上使用MySQLdb的Python ImportError(El Capitan)

时间:2016-10-08 13:47:19

标签: python mysql macos anaconda mysql-python

我使用以下方法在El Capitan上安装了MySQLdb:

brew install mysql
pip install MySQL-python

当我尝试python -c "import MySQLdb"时,我收到以下错误:

  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

找到一些相关的帖子,但仍然没有弄清楚如何解决这个问题。非常感谢任何帮助。

修改 如果我决定恢复步骤1(brew uninstall mysql),因为SQLite(sqlite3)预先安装了El Capitan,我收到以下错误消息:

  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 

我错过了什么?这两条错误消息是否相关?

1 个答案:

答案 0 :(得分:0)

我之后得到了一个错误,我认为,自制的更新了mysql。通过运行pip uninstall mysqlclient && pip install mysqlclient,我无需设置DYLD_LIBRARY_PATH就可以重新开始工作。