pip安装mysqlclient依赖报错 /bin/sh: 1: mysql_config: not found如何解决

报错信息:

Collecting mysqlclient==2.1.0
  Downloading https://mirrors.aliyun.com/pypi/packages/de/79/d02be3cb942afda6c99ca207858847572e38146eb73a7c4bfe3bdf154626/mysqlclient-2.1.0.tar.gz (87 kB)
     |████████████████████████████████| 87 kB 441 kB/s 
    ERROR: Command errored out with exit status 1:
     command: /root/.pyenv/versions/3.9.5/envs/hm_bundle_schedule/bin/python3.9 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-79l21ek7/mysqlclient_1a7c70c578a94ec4b5df3c3a3db9c3d5/setup.py'"'"'; __file__='"'"'/tmp/pip-install-79l21ek7/mysqlclient_1a7c70c578a94ec4b5df3c3a3db9c3d5/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-j8yuji7i
         cwd: /tmp/pip-install-79l21ek7/mysqlclient_1a7c70c578a94ec4b5df3c3a3db9c3d5/
    Complete output (15 lines):
    /bin/sh: 1: mysql_config: not found
    /bin/sh: 1: mariadb_config: not found
    /bin/sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "", line 1, in 
      File "/tmp/pip-install-79l21ek7/mysqlclient_1a7c70c578a94ec4b5df3c3a3db9c3d5/setup.py", line 15, in 
        metadata, options = get_config()
      File "/tmp/pip-install-79l21ek7/mysqlclient_1a7c70c578a94ec4b5df3c3a3db9c3d5/setup_posix.py", line 70, in get_config
        libs = mysql_config("libs")
      File "/tmp/pip-install-79l21ek7/mysqlclient_1a7c70c578a94ec4b5df3c3a3db9c3d5/setup_posix.py", line 31, in mysql_config
        raise OSError("{} not found".format(_mysql_config_path))
    OSError: mysql_config not found
    mysql_config --version
    mariadb_config --version
    mysql_config --libs
    ----------------------------------------
WARNING: Discarding https://mirrors.aliyun.com/pypi/packages/de/79/d02be3cb942afda6c99ca207858847572e38146eb73a7c4bfe3bdf154626/mysqlclient-2.1.0.tar.gz#sha256=973235686f1b720536d417bf0a0d39b4ab3d5086b2b6ad5e6752393428c02b12 (from https://mirrors.aliyun.com/pypi/simple/mysqlclient/) (requires-python:>=3.5). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement mysqlclient==2.1.0 (from versions: 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.3.8, 1.3.9, 1.3.10, 1.3.11rc1, 1.3.11, 1.3.12, 1.3.13, 1.3.14, 1.4.0rc1, 1.4.0rc2, 1.4.0rc3, 1.4.0, 1.4.1, 1.4.2, 1.4.2.post1, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.1.0rc1, 2.1.0, 2.1.1, 2.2.0rc1, 2.2.0)
ERROR: No matching distribution found for mysqlclient==2.1.0
WARNING: You are using pip version 21.1.1; however, version 23.2.1 is available.
You should consider upgrading via the '/root/.pyenv/versions/3.9.5/envs/hm_bundle_schedule/bin/python3.9 -m pip install --upgrade pip' command

原因:系统中没有安装mysql的开发包

解决办法:

mysql_config是MySQL的一个工具,用于检查和配置MySQL的安装路径和编译选项。

要解决这个问题,可以尝试以下几个步骤:

Ubuntu或Debian:

sudo apt-get install libmysqlclient-dev

CentOS或RHEL:

sudo yum install mysql-devel
macOS(使用Homebrew):

brew install mysql
Windows(使用MinGW):

mingw-get install libmysql
安装完MySQL的开发包后,再次运行您的命令,问题解决

你可能感兴趣的:(运维,python,pip,mysql,数据库)