注意:如果你用的是python3.x,直接去看第四个问题
遇到的第一个问题
正常来说直接执行pip安装,就是可以的,但是MySQL-python偏偏比较独特
pip install MySQL-python
报错
_mysql.c:44:10: fatal error: 'my_config.h' file not found
#include "my_config.h"
^~~~~~~~~~~~~
1 error generated.
error: command 'cc' failed with exit status 1
解决第一个问题
执行brew install mysql-connector-c
brew install mysql-connector-c
如果这一步直接完成,那就可以继续pip install MySQL-python了,应该会成功
但是我在这一步执行失败了
遇到第二个问题
brew install mysql-connector-c报错
Error: Cannot install mysql-connector-c because conflicting formulae are installed.
mysql: because both install MySQL client libraries
Please `brew unlink mysql` before continuing.
解决第二个问题
按照报错的提示,执行brew unlink mysql
没有发生什么意外,执行完毕,继续执行brew install mysql-connector-c
'mysql-connector-c'安装成功
执行brew link --overwrite mysql,重新连接mysql(这一步我没有做)
然后再执行pip install MySQL-python,如果成功了就搞定了
神奇的是,我在这一步又失败了
遇到的第三个问题
上面的步骤走完以后,执行pip install MySQL-python,报错
Collecting mysql
Downloading https://files.pythonhosted.org/packages/06/ef/c4efbf2a51fb46aba9be03a973638d9539c9ca10a5259b2cbb1a66133b2e/mysql-0.0.1.tar.gz
Collecting MySQL-python (from mysql)