Python MySQLClient安装失败,并显示“metadata-generation-failed”

hs1ihplo  于 2023-04-10  发布在  Mysql
关注(0)|答案(5)|浏览(504)

好吧,我已经“google了一下”,没有找到答案。基于Python的站点的常规更新,基于它的requirements.txt,现在在尝试更新“mysqlclient”时会失败,并显示元数据生成失败。问题是为什么。

eeq64g8w

eeq64g8w1#

  • 罗宾逊的 * 答案是正确的,但也可能是你忘记安装MySQL开发头和库了,比如:
$ sudo apt-get install default-libmysqlclient-dev

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

s4n0splo

s4n0splo2#

相关信息如下:

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:未找到命令
我通过定位命令在我的系统上的位置,并将其添加到$PATH来解决问题,在我的情况下如下所示:

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

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

3yhwsihp

3yhwsihp3#

简短回答

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和安装成功.

eyh26e7m

eyh26e7m4#

假设requirements.txt包含一个'import mysql'语句,MySQL documentation帮助可以通过两种方式解决这个问题:
1.由于mysql是一个“虚拟包”,请安装“MySQL-python(Python 2)或mysqlclient(Python 3)”
1.解析OS specific install dependencies
一旦依赖项被安装,你就可以通过安装mysql包来避免代码重写。

x6h2sr28

x6h2sr285#

不确定这是否仍然有帮助。在我的情况下,我意识到这一点
sudo apt-get install default-libmysqlclient-dev
我安装了mysql客户端,但没有安装mysql服务器。我安装了mysql服务器:
sudo apt install mysql-server
这样就解决了问题

相关问题