使用 pip 安装 mySQLDB 时出错手动指定 MYSQLCLIENT_CFLAGS 和 MYSQLCLIENT_LDFLAGS 环境变量

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

无法在运行 python3.9 的最新 amazon Linux AL2023 中运行 django 应用程序

它报告 mySQLDB 模块未安装,我尝试使用 pip 和 yum 安装 mysql 模块,但没有任何帮助解决问题。我们得到的错误是“手动指定 MYSQLCLIENT_CFLAGS 和 MYSQLCLIENT_LDFLAGS 环境变量”

    backend = load_backend(db["ENGINE"])
  File "/data/vpy38/lib/python3.9/site-packages/django/db/utils.py", line 113, in load_backend
    return import_module("%s.base" % backend_name)
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/data/vpy38/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient? 

当我尝试通过 pip 安装它时,出现以下错误:

Collecting mysqlclient
  Using cached mysqlclient-2.2.4.tar.gz (90 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
  ╰─> [24 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.
      Trying pkg-config --exists libmariadb
      Command 'pkg-config --exists libmariadb' returned non-zero exit status 1.
      Traceback (most recent call last):
        File "/data/vpy38/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/data/vpy38/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/data/vpy38/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/tmp/pip-build-env-0ehmrzaq/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 327, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
        File "/tmp/pip-build-env-0ehmrzaq/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 297, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-0ehmrzaq/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 313, in run_setup
          exec(code, locals())
        File "<string>", line 155, in <module>
        File "<string>", line 49, in get_config_posix
        File "<string>", line 28, in find_package_name
      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. 

操作系统:Amazon Linux2023 Python3.9

请帮我解决。

python pip mysql-python
1个回答
0
投票

要在 Linux 上安装

mysqlclient
,您可能需要安装 Python 3 和 MySQL 开发头文件和库,如下所示:

$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config # Debian / Ubuntu
% sudo yum install python3-devel mysql-devel pkgconfig # Red Hat / CentOS

然后你现在可以通过pip安装mysqlclient了:

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