python - 无法在 ubuntu 上使用 pip 安装 mysqlclient

标签 python mysql django ubuntu pip

这个问题在这里已经有了答案:





pip install mysql-python fails with EnvironmentError: mysql_config not found

(24 个回答)



mysql_config not found when installing mysqldb python interface

(34 个回答)


6 个月前关闭。




我正在尝试在 Ubuntu 20.04LTS 上安装 mysqlclient,主要错误是:找不到 mysql_config。
整个错误:

$ pip3 install mysqlclient==2.0.3
Defaulting to user installation because normal site-packages is not writeable
Collecting mysqlclient==2.0.3
  Using cached mysqlclient-2.0.3.tar.gz (88 kB)
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qr1hc7jz/mysqlclient_1ff152ec2d5d4f14a4e282285faeb229/setup.py'"'"'; _file__='"'"'/tmp/pip-install-qr1hc7jz/mysqlclient_1ff152ec2d5d4f14a4e282285faeb229/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file_) if os.path.exists(_file_) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, _file_, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ehrlbbbl
       cwd: /tmp/pip-install-qr1hc7jz/mysqlclient_1ff152ec2d5d4f14a4e282285faeb229/
  Complete output (15 lines):
  /bin/sh: 1: mysql_config: not found
  /bin/sh: 1: mariadb_config: not found
  /bin/sh: 1: mysql_config: not found
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-qr1hc7jz/mysqlclient_1ff152ec2d5d4f14a4e282285faeb229/setup.py", line 15, in <module>
      metadata, options = get_config()
    File "/tmp/pip-install-qr1hc7jz/mysqlclient_1ff152ec2d5d4f14a4e282285faeb229/setup_posix.py", line 70, in get_config
      libs = mysql_config("libs")
    File "/tmp/pip-install-qr1hc7jz/mysqlclient_1ff152ec2d5d4f14a4e282285faeb229/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
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/3c/df/59cd2fa5e48d0804d213bdcb1acb4d08c403b61c7ff7ed4dd4a6a2deb3f7/mysqlclient-2.0.3.tar.gz#sha256=f6ebea7c008f155baeefe16c56cd3ee6239f7a5a9ae42396c2f1860f08a7c432 (from https://pypi.org/simple/mysqlclient/) (requires-python:>=3.5). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement mysqlclient==2.0.3 (from versions: 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.3.8, 1.3.9, 1.3.10, 1.3.11rc1, 1.3.11, 1.3.12, 1.3.13, 1.3.14, 1.4.0rc1, 1.4.0rc2, 1.4.0rc3, 1.4.0, 1.4.1, 1.4.2, 1.4.2.post1, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.1.0rc1, 2.1.0)
ERROR: No matching distribution found for mysqlclient==2.0.3
(尝试 pip3 安装 mysqlclient 时,出现相同的错误,但每个版本都尝试安装)

最佳答案

您需要像在您的 ubuntu 操作系统中一样安装 python3 和 MySQL 开发头文件和库,

sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
然后使用安装
pip3 install mysqlclient==2.0.3
我希望这会帮助你

关于python - 无法在 ubuntu 上使用 pip 安装 mysqlclient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70315196/

相关文章:

python - jsonify Flask 中的 SQLAlchemy 结果集

python - cv2.videocapture.read() 不返回 numpy 数组

java - 为什么 Runtime.getRuntime().exec 在 Tomcat 中以 root 身份 fork 进程?

python - 使用fast-ai时如何修复 'Error(s) in loading state_dict for AWD_LSTM'

mysql - 如何在 MySQL 中进行随机排序。我应该使用 random() 还是 uuid()

python - 全局变量 Django

django - 在 Geodjango 应用程序中将几何点转换为纬度/经度

php - post 方法不适用于 zend 框架中的表单装饰器

MYSQL - 以不同格式 dd-mm-yy 存储的日期 - 无法检索值

python - 自定义 Django Crispy 表单中忽略了 ValidationError