报错信息:
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 "<string>", line 1, in <module>
File "/tmp/pip-install-79l21ek7/mysqlclient_1a7c70c578a94ec4b5df3c3a3db9c3d5/setup.py", line 15, in <module>
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:
解决方案
安装 Python 开发头文件
首先,你需要安装 Python 的开发包。这个包包含了编译 C 扩展模块所需的头文件和静态库:
sudo apt install python3-dev
安装编译所需的其他工具
确保安装了构建工具,这些工具可以帮助你编译和构建 Python 包:
sudo apt install build-essential
确认 MySQL 开发包已安装
为了成功构建 mysqlclient,你可能还需要安装 MySQL 客户端开发包:
sudo apt install libmysqlclient-dev
用 wheel 防止 legacy build(可选)
虽然 wheel 不是必需的,但它可以让很多包使用更高效的 Wheel 格式而不是通过 setup.py 构建:
pip install wheel
重新尝试安装包
在配置好以上开发环境后,再次尝试安装 mysqlclient:
pip install mysqlclient