Error "No module named 'MySQLdb'" When Loading MySQL Module
When working with a Django project using SQL in a Windows 10 command line with Python 3.4, you may encounter an error message:
File "C:\Users\user\env\lib\site-packages\django\db\backends\mysql\base.py", line 30, in <module> 'Did you install mysqlclient or MySQL-python?' % e django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. Did you install mysqlclient or MySQL-python?
Despite installing mysqlclient with pip install mysqlclient==1.3.5, you still encounter this issue. To resolve this, you need to:
Install PyMySQL using:
pip install pymysql
Add the following lines to it:
import pymysql pymysql.install_as_MySQLdb()
This will import the PyMySQL module and install it as MySQLdb, allowing Django to recognize and utilize it for database connections.
The above is the detailed content of Why Does Django Show \'No module named \'MySQLdb\'\' and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!