Mysqlclient无法通过pip安装,找不到pkg-config名称

问题描述 投票:0回答:4

我对 Linux 和 VM 总体来说还是个新手。我目前正在尝试在干净的 Ubuntu Jammy 64 (22.4) vbox 实例上安装 mysqlclient。预先运行以下命令:

    sudo add-apt-repository universe
    sudo apt-get install net-tools -y
    sudo apt-get install python3 -y
    sudo apt-get install python3-pip -y
    pip install pkgconfig
    sudo apt-get install pkg-config -y

当我尝试运行

pip install mysqlclient
时,出现以下错误:

vagrant@Ctrl-A-EES:~$ pip install mysqlclient
Defaulting to user installation because normal site-packages is not writeable
Collecting mysqlclient
  Using cached mysqlclient-2.2.0.tar.gz (89 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      Trying pkg-config --exists mysqlclient
      Command 'pkg-config --exists mysqlclient' returned non-zero exit status 1.
      Trying pkg-config --exists mariadb
      Command 'pkg-config --exists mariadb' returned non-zero exit status 1.
      Traceback (most recent call last):
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 162, in get_requires_for_build_wheel
          return self._get_build_requires(
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 143, in _get_build_requires
          self.run_setup()
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 158, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 154, in <module>
          ext_options = get_config_posix(get_options())
        File "setup.py", line 48, in get_config_posix
          pkg_name = find_package_name()
        File "setup.py", line 27, in find_package_name
          raise Exception(
      Exception: Can not find valid pkg-config name.
      Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

任何建议都会有很大帮助!谢谢!

预计安装将顺利解决。尝试解决 pkg-config 依赖关系,但无济于事。

pip mysql-python ubuntu-22.04 libmysqlclient
4个回答
12
投票

就我而言,

sudo apt install pkg-config
足以运行
pip install mysqlclient


8
投票

FlyingTeller 的解决方案:

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

修复了依赖关系。


0
投票

您在尝试使用 pip3 安装

mysqlclient
时遇到的错误与缺少
pkg-config
及其无法找到构建包所需的依赖项有关。

pkg-config
找不到构建
mysqlclient
Python 包所需的
mariadb
mysqlclient
库。

尝试这些解决方案:

  1. sudo apt-get update && sudo apt-get install python3-dev default-libmysqlclient-dev

如果以上方法不起作用:

  1. 您可以按照错误消息中的建议,通过手动指定
    MYSQLCLIENT_CFLAGS
    MYSQLCLIENT_LDFLAGS
    环境变量的路径来尝试安装 mysqlclient 库。

sudo MYSQLCLIENT_CFLAGS="-I/usr/include/mysql" MYSQLCLIENT_LDFLAGS="-L/usr/lib/x86_64-linux-gnu -lmysqlclient" pip3 install mysqlclient

注意:如果

/usr/include/mysql
/usr/lib/x86_64-linux-gnu
位于其他位置,请将其替换为系统上
mysqlclient
标头和库文件的正确路径。提供的路径对于基于 Ubuntu 的系统是常见的。


0
投票

将此用于 Debian/Ubuntu

sudo apt-get update
sudo apt-get install gcc libmysqlclient-dev python3-dev

将其用于 Fedora:

sudo dnf install gcc mysql-devel python3-devel

然后再次运行

pip install mysqlclient
© www.soinside.com 2019 - 2024. All rights reserved.