Mac+Python3环境安装mysqlclient包:OSError: mysql_config not found

Django默认使用了sqlite数据库,实际过程中往往使用其他数据库,例如mysql。

Django项目连接MySQL数据库必须要安装相应的驱动包,由于是Python3所以这里使用了mysqlclient包。

在安装mysqlclient前需要安装mysql-connector-c,使用brew来进行安装(如果没有安装homebrew请参考其他博文),在终端输入:

brew install mysql-connector-c 

之后直接在pycharm或者终端pip安装mysqlclient包会发生报错,核心错误应该是

OSError: mysql_config not found
 意思是找不到mysql的配置。

解决方案来自mysqlclient的GitHub官网https://github.com/PyMySQL/mysqlclient-python

# 确保已经进入Python3的虚拟环境了,依次在终端中执行以下命令。
brew install mysql-client
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
export PATH="/usr/local/opt/mysql-client/bin:$PATH"
pip install mysqlclient

猜你喜欢

转载自blog.csdn.net/muzihuaner/article/details/129659894
今日推荐