简体   繁体   English

OS X El Capitan上的MySQLdb错误

[英]Error with MySQLdb on OS X El Capitan

I tried importing the MySQLdb within iPython and received the following error. 我尝试在iPython中导入MySQLdb并收到以下错误。

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. 我在Stackoverflow上找到了几条类似的帖子,建议我禁用系统完整性保护。

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. 我还按照OSX El Capitan在本文中建议的方式编辑了bashprofile,即Python mysqldb:未加载库:libmysqlclient.18.dylib,但我仍然无法克服此问题。

A little more information incase it helps diagnose the issue: 更多信息,以帮助诊断问题:

  • Python version: Python 2.7.10 |Anaconda 2.4.0 (x86_64)| Python版本: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)] (默认值,2015年10月19日,18:31:17)[GCC 4.2.1(Apple Inc.内部版本5577)]
  • Result of 'which python' : /Users/user1/anaconda/bin/python '哪个python'的结果:/ Users / user1 / anaconda / bin / python
  • MySQL Version installed: mysql-5.7.10 安装的MySQL版本:mysql-5.7.10
  • MySQL-Python version: MySQL-python-1.2.5 MySQL-Python版本:MySQL-python-1.2.5

Where am I going wrong? 我要去哪里错了?

After some research, I figured that the issue might have been due to OpenSSL, and permissions related to this in El Capitan. 经过研究,我发现问题可能是由于OpenSSL,以及El Capitan中与此相关的权限所致。 I found two resources which hinted at similar solutions: 我发现了两个资源,它们暗示了类似的解决方案:

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

So here it is: 所以这里是:

brew install --upgrade openssl
brew unlink openssl && brew link openssl --force

你可以试试:

 export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

I had the same problem and tried a few things including the brew install, unlink, link solution without any luck. 我遇到了同样的问题,尝试了一些事情,包括brew安装,取消链接,没有任何运气的链接解决方案。 For OS X 10.12.3 running Python 2.7.12, Anaconda 2.3.0 the following worked for me. 对于运行Python 2.7.12,Anaconda 2.3.0的OS X 10.12.3,以下代码对我有用。

  1. Turn off System Integrity Protection: Reboot the Mac and hold down Command + R, open the terminal and enter: csrutil disable; 关闭系统完整性保护:重新启动Mac并按住Command + R,打开终端,然后输入: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/ 重启后:cd /usr/local/Cellar/openssl/1.0.2k/lib sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib / usr / lib /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM