ImportError: No module named MySQLdb in Python Django
Hello, I am a newbie in Python I was beginning to learn Python two months ago. I have created a simple web application with Python.
I am using Python version 3.9.7 and installing MySQL version 8.0 and Django
I create a file function help connect to MySQL as below:
But when I ran the code above I got an exception throw : ImportError: No module named MySQLdb.
Any suggestions for me?
-
d1
dang nhat hai long Nov 20 2021
I saw you import MySQLdb in your code to help connect to the MySQL database.
You have to install two packages are
mysql-connector-python
andmysql-python
. To install them you can run the command below:pip install mysql-connector-python pip install mysql-python
I hope it solve for you.
-
W-1
Watcharapong Jakkawannorasing Nov 20 2021
You need to install
libmysqlclient-dev
package first, by using command :sudo apt install libmysqlclient-dev
and THENFor python 2.x run command:
pip install mysql-python
For python 3.x run command:
pip install mysqlclient
This solution worked for me.
-
R-2
Raja T Nov 20 2021
We have 3 packages that need to install to help connect to MYSQL:
1. Install the
mysqlclient
package:pip install mysqlclient
2. Install the
mysql-connector-python
packaged:pip install mysql-connector-python
3. Install the
pymysql
package:pip install pymysql
After all is done, you can re-try run your code.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.