📌  相关文章
📜  ModuleNotFoundError:Windows 中没有名为“MySQLdb”的模块 - Python (1)

📅  最后修改于: 2023-12-03 15:02:59.212000             🧑  作者: Mango

ModuleNotFoundError: No module named 'MySQLdb' - Python

When trying to execute a script that requires the MySQLdb module in Python, you may encounter the following error message:

ModuleNotFoundError: No module named 'MySQLdb'

This error occurs because the MySQLdb module is not included in the official Python distribution. Instead, you must install the module separately before it can be used.

One solution to this error is to install the mysqlclient module, which is a fork of the MySQLdb module and works as a drop-in replacement:

pip install mysqlclient

Alternatively, if you prefer to use the original MySQLdb module, you can install it using the following command:

pip install MySQL-python

Note that this requires that you have the MySQL development headers installed on your system.

Once you have installed either the mysqlclient or MySQLdb module, you should be able to import and use it in your Python scripts without encountering the ModuleNotFoundError.