目的
在python3环境中,可以执行如下命令:import MySQLdb
准备环境
apt-get update
apt-get install python3-pip
apt-get install libmysqlclient-dev
pip3 install mysqlclient
报错:
Exception: Can not find valid pkg-config name.
Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
解决方法:
apt-get install pkg-config
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> exit()
ps:
实在不行,可以试试:
sudo apt-get install python-dev libmysqlclient-dev
sudo apt-get install python3-dev
pip install mysqlclient