Mac 上的 MySQLdb 安装问题。 MySQL 与 Django 连接所需

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

我正在 Mac 上创建一个 Django 项目。我想使用 MySQL 作为数据库。我正在尝试安装 MySQLdb,但出现以下错误:

(djangodev) $ pip3 install MySQL-python                                                                 

Collecting MySQL-python
  Using cached MySQL-python-1.2.5.zip (108 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/9z/lf5bsw2929j34m5g6g9qcfqm0000gn/T/pip-install-5qv449ur/mysql-python_191252dd91f14deab09b6860c8c503d9/setup.py", line 13, in <module>
          from setup_posix import get_config
        File "/private/var/folders/9z/lf5bsw2929j34m5g6g9qcfqm0000gn/T/pip-install-5qv449ur/mysql-python_191252dd91f14deab09b6860c8c503d9/setup_posix.py", line 2, in <module>
          from ConfigParser import SafeConfigParser
      ModuleNotFoundError: No module named 'ConfigParser'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
python mysql django mysql-python libmysqlclient
1个回答
0
投票

MySQL-python 与 Python 3 不兼容。MySQL-python 仅与 Python 2 兼容,因为 ConfigParser 在 Python 3 中已重命名为 configparser。

要安装mysqlclient,可以运行以下命令

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