Mac os 安装Mysql-Python

Mac os 安装Mysql-python

安装环境情况

安装命令

pip install MySql-python

通常这样是行不通的

安装前的准备

0. brew install mysql
1. brew unlink mysql # 如果已经安装
2. brew install mysql-connector-c # 安装mysql依赖文件
3. which mysql_config # 查看本地mysql_config 文件在哪
4. vim mysql_config 找到
libs="$libs -l"
替换为
lib="$libs -lmysqlclient -lssl -lcrypto"
# 新版mysql可能已经替换
5. pip install mysqlclinet
6. pip install MySql-python
7. brew unlink mysql-connector-c
8. brew link mysql

遇见错误

_mysql.c:36:10: fatal error: 'my_config.h' file not found
#include "my_config.h"
^~~~~~~~~~~~~
1 error generated.
error: command 'cc' failed with exit status 1

错误原因

1. 未安装mysql-connector-c 缺少对应库
2. 安装了新版的mysql默认没有my_config文件

**这是mysql 8.0.19默认库文件,确实没有my_config.h,这个时候我们需要copy一份

将mysql.h copy 一份重命名为 my_config.h

然后在进行安装即可

pip install MySql-python

参考stackoverflow,原文:stackoverflow

Author

ol4three

Posted on

2020-08-01

Updated on

2021-03-03

Licensed under


Comments