安装 mysqlclient 报 mysql_config not found

安装 mysqlclient 报 mysql_config not found

raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found

发现原来是用 apt 安装的 mysql 的 mysql_config 文件缺失了,
需要安装 libmysqld-dev 和 libmysqlclient-dev 两个包。

如果安装时少了 libmysqld-dev 就会报这个错,

n__=1.3.12 -I/usr/include/mysql -I/usr/include/python3.6m -c _mysql.c -o build/temp.linux-x86_64-3.6/_mysql.o
    _mysql.c: In function ‘_mysql_ConnectionObject_ping’:
    _mysql.c:1894:3: error: unknown type name ‘my_bool’; did you mean ‘_Bool’?
       my_bool recon = reconnect;
       ^~~~~~~
       _Bool
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-p5vupszb/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-q5zxo5am/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-p5vupszb/mysqlclient/

如果安装 libmysqld-dev 出现依赖关系的 bug,就要安装正确的依赖版本:

下列软件包有未满足的依赖关系:
 libmysqld-dev : 依赖: libmysqlclient-dev (>= 5.7.22-0ubuntu18.04.1) 但是它将不会被安装
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。

根据提示 libmysqlclient-dev (>= 5.7.22-0ubuntu18.04.1)可以安装:

sudo apt install libmysqlclient-dev=5.7.22-0ubuntu18.04.1

最后再重新安装 mysqlclient

sudo pip install mysqlclient --user

你可能感兴趣的:(安装 mysqlclient 报 mysql_config not found)