Mac+Python3 environment to install the mysqlclient package: OSError: mysql_config not found

Django uses the sqlite database by default, and other databases, such as mysql, are often used in the actual process.

The corresponding driver package must be installed for the Django project to connect to the MySQL database. Since it is Python3, the mysqlclient package is used here.

Before installing mysqlclient, you need to install mysql-connector-c, use brew to install (if homebrew is not installed, please refer to other blog posts), enter in the terminal:

brew install mysql-connector-c 

After installing the mysqlclient package directly in pycharm or terminal pip, an error will occur, and the core error should be

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

The solution comes from the GitHub official website of mysqlclient 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

Guess you like

Origin blog.csdn.net/muzihuaner/article/details/129659894