欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

安装mysqlclient报mysql_config not found

程序员文章站 2022-05-29 11:34:35
...
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