python 3 / 没有名为 'MySQLdb' 的模块



当我试图获得一些数据与我的flask应用程序:

Traceback (most recent call last):
File "~/server/env/lib/python3.9/site-packages/sqlalchemy/util/_collections.py", line 1008, in __call__
return self.registry[key]
KeyError: 6166425600

这个回溯结束于:

File "~/server/env/lib/python3.9/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 163, in dbapi
return __import__("MySQLdb")
ModuleNotFoundError: No module named 'MySQLdb'

当我尝试pip安装mysqlclient(推荐的修复)时,我得到:

Collecting mysqlclient
Using cached mysqlclient-2.1.0.tar.gz (87 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/private/var/folders/j5/b194wjbn32sbqct7crpvcp2w0000gn/T/pip-install-ijejonzz/mysqlclient_841539cf1eed4511a135f8e95cb2be75/setup.py", line 15, in <module>
metadata, options = get_config()
File "/private/var/folders/j5/b194wjbn32sbqct7crpvcp2w0000gn/T/pip-install-ijejonzz/mysqlclient_841539cf1eed4511a135f8e95cb2be75/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/private/var/folders/j5/b194wjbn32sbqct7crpvcp2w0000gn/T/pip-install-ijejonzz/mysqlclient_841539cf1eed4511a135f8e95cb2be75/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
[end of output]

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

不知道还能做什么,除了PIP安装。

您的机器上安装了MySQL吗?Pip只安装python连接器,它失败了,因为它找不到本地安装的MySQL或MariaDB。

最新更新