[ModuleNotFoundError:没有名为“MySQLdb”的模块]

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

我正在尝试通过 pip 安装

mysqlclient
库,但出现此错误:

kanishka@kanishka-VivoBook-ASUSLaptop-X512FJ-X512FJ:~/Documents/Ceylone Soft/bcj_dev_back_end$ pip install mysqlclient

Collecting mysqlclient
  Using cached mysqlclient-2.2.4.tar.gz (90 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: '/home/kanishka/Documents/Ceylone Soft/bcj_dev_back_end/BuyChem/bin/python3' /tmp/tmp81chy8bh get_requires_for_build_wheel /tmp/tmpbjs9srac
       cwd: /tmp/pip-install-ulmsnxu3/mysqlclient
  Complete output (24 lines):
  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 "/tmp/tmp81chy8bh", line 280, in <module>
      main()
    File "/tmp/tmp81chy8bh", line 263, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/tmp/tmp81chy8bh", line 114, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/tmp/pip-build-env-csmolp15/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "/tmp/pip-build-env-csmolp15/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
      self.run_setup()
    File "/tmp/pip-build-env-csmolp15/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 311, 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
  ----------------------------------------
ERROR: Command errored out with exit status 1: '/home/kanishka/Documents/Ceylone Soft/bcj_dev_back_end/BuyChem/bin/python3' /tmp/tmp81chy8bh get_requires_for_build_wheel /tmp/tmpbjs9srac Check the logs for full command output.
python mysql-python
1个回答
0
投票

您的错误消息表明您应该

Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually

mysqlclient 默认使用

pkg-config --cflags --ldflags mysqlclient
来查找编译器/链接器标志。

您可以使用

MYSQLCLIENT_CFLAGS
MYSQLCLIENT_LDFLAGS
环境变量来自定义编译器/链接器选项。

$ export MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags`
$ export MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs`
$ pip install mysqlclient

参见https://pypi.org/project/mysqlclient/#description

© www.soinside.com 2019 - 2024. All rights reserved.