前提:
mac os: 10.13.4
python: 2.7.15 通过Anaconda安装
mysql: 8.x 通用官网安装
过程:
一开始使用命令 pip install mysql-python ,报错说my_config.h文件找不到。
于是google : https://stackoverflow.com/questions/50864438/mac-pip-install-mysql-python-unsuccessful
根据答案,选安装connector
brew install mysql-connector-c pip install MySQL-python
然后报出新问题,说是string index out of range索引越界。
再次google: https://stackoverflow.com/questions/43543483/pip-install-mysql-python-fails-with-indexerror/43543677
说是brew安装connector时搞了问题,需要修改/usr/local/bin/mysql_config这个文件,
将
#Create options Libs = "-L $ pkglibdir " Libs = " $ libs -l"
改为
#Create options Libs = "- L $ pkglibdir" Libs = "$ libs -lmysqlclient -lssl -lcrypto"
之后再运行
pip install mysql-python
安装成功!
在python中输入
import MySQLdb
没有报错!
世界终于美好了~~~~