mac下python安装MySQLdb模块

mac下python安装MySQLdb模块

[2]博客文章 python

运行的代码中有import MySQLdb语句报错,安装时趟了无数坑,网上找到的各种教程很多不靠谱的。终于装成功,特此记录,以免后来人再趟坑。

报错信息:

ImportError: dlopen(/Users/huwenchao/anaconda/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
  Referenced from: /Users/huwenchao/anaconda/lib/python2.7/site-packages/_mysql.so
  Reason: image not found

解决方法:

  1. 安装有关程序
    brew install mysql --universal
    pip install MySQL-python
    
  2. openssl相关文件复制到/usr/lib
    cd /usr/local/Cellar/openssl/1.0.1i/lib
    sudo cp libcrypto.1.0.0.dylib libssl.1.0.0.dylib /usr/lib
    

参考链接:

  1. http://blog.csdn.net/artwebs/article/details/8727603
  2. http://hearrain.com/2011/01/494
  3. http://stackoverflow.com/questions/11365619/psycopg2-installation-error-library-not-loaded-libssl-dylib

你可能感兴趣的:(编程实践)