Python MySQLClient 安装失败,"metadata-generation-failed"



我在谷歌上搜索过了没有找到答案。基于python的站点基于其requirements.txt的例行更新现在使用元数据生成失败失败当试图更新mysqlclient."问题是为什么。

Robinson的答案是正确的,但也可能你忘记安装MySQL开发头文件和库像这样:

$ sudo apt-get install default-libmysqlclient-dev

详细信息:https://pypi.org/project/mysqlclient/

相关消息文本如下:

Collecting mysqlclient
Using cached mysqlclient-2.1.0.tar.gz (87 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/private/var/folders/zv/60vkqgms41v8zg76_n8rntg00000gn/T/pip-install-_nlyaw6p/mysqlclient_a781e05976524422b764a6902ff6fe88/setup.py", line 15, in <module>
metadata, options = get_config()
File "/private/var/folders/zv/60vkqgms41v8zg76_n8rntg00000gn/T/pip-install-_nlyaw6p/mysqlclient_a781e05976524422b764a6902ff6fe88/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/private/var/folders/zv/60vkqgms41v8zg76_n8rntg00000gn/T/pip-install-_nlyaw6p/mysqlclient_a781e05976524422b764a6902ff6fe88/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
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
mysql_config: command not found

通过定位命令在我的系统上的位置,并将其添加到$PATH来解决问题,在我的情况下,如下所示:

export PATH=/usr/local/mysql-5.7.16-osx10.11-x86_64/bin:$PATH

很明显,这个消息的意思是配置mysql的命令在$PATH上找不到。现在我们知道了

简短回答

sudo apt-get install python3.10-dev default-libmysqlclient-dev build-essential

python3.10-dev中的python版本应该是您使用的python版本。在我的情况下,它是3.10:

$ python3 --version
Python 3.10.6

详细信息首先,我运行了@levinson的命令:

sudo apt-get install default-libmysqlclient-dev

然后在pip install -r requirements.txt期间,我得到了其他错误(相互继承):

Building wheel for mysqlclient (setup.py) ... error
error: subprocess-exited-with-error
<...>
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
<...>
Running setup.py install for mysqlclient ... error
error: subprocess-exited-with-error
<...>
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

在那之后,我发现了这篇文章,它建议执行这个命令:

# For Debian/ Ubuntu
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential

但它给了我错误,而安装python3-dev。在那之后,我发现有一个python3.x-dev软件包,并尝试了3.10版本。这招奏效了!在那之后,我只是运行pip install -r requirements.txt和安装成功。

不确定这是否仍然有帮助。在我的例子中,我意识到

sudo apt-get install default-libmysqlclient-dev

正在安装mysql客户端而不是mysql服务器。我安装mysql服务器:

sudo apt install mysql-server

,这解决了这个问题。

假设requirements.txt中包含'import mysql'语句,mysql文档可以通过两种方式帮助解决这个问题:

  1. 由于mysql是一个'虚拟包',请安装" mysql - Python (Python 2)或mysqlclient (Python 3)">
  2. 解决操作系统特定的安装依赖

一旦安装了依赖项,你可以通过安装mysql包来避免代码重写。

在终端执行以下步骤!!

  1. brew install mysql

  2. brew install openssl

  3. 出口路径= ${}路径:/usr/地方/mysql/bin/

  4. sudo xcode-select——reset

  5. pip install mysqlclient

相关内容

最新更新