最近在跑一个新 Python 项目, 需要安装 MySQL-python
,但是执行 pip install MySQL-python
的时候报了以下错误
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
搜索后在 这里 找到解决方案
我的开发环境是
- python2.7
- pip9.0.1
- mysql5.7
- Ubuntu18.04
在执行 sudo apt-get install libmysqlclient-dev
的时候又报了如下错误
The following packages have unmet dependencies:
libmysqlclient-dev : Depends: libmysqlclient20 (= 5.7.21-1ubuntu1) but 5.7.22-0ubuntu18.04.1 is to be installed
E: Unable to correct problems, you have held broken packages.
根据上面提示,大概原因是:Ubuntu18.04 默认安装的 libmysqlclient20=5.7.22-0ubuntu18.04.1
, 这个时候再执行安装 sudo apt-get install libmysqlclient-dev
,会报以下错误
所以解决办法是,卸载新版本 libmysqlclient20=5.7.22-0ubuntu18.04.1
, 安装老版本 libmysqlclient20=5.7.21-1ubuntu1
执行以下命令
sudo apt autoremove libmysqlclient20
sudo apt install libmysqlclient20=5.7.21-1ubuntu1
目前是解决了问题,但是不知道后续有没有兼容性的后遗症