Error loading MySQLdb module: No module named 'MySQLdb'
MySQLdb is only for Python 2.x. You can't install in Python 3.x versions. Now from your question i can see that you are working with Django. In this case you have three alternatives, from Django mysql notes:
- mysqldb
- mysqlclient
- mysql-connect-python
This gives to you two alternatives, mysqlclient and mysql-connect-python, The first one requires compilation from extensions for the plugin and, in Windows, this implies VStudio Libraries and a know-how for compile native extensions.
mysql-connect-python is not compiled (and i don't recommend this for production, maybe only for dev) so you are going to need to install this.
You can try:
pip3 install mysql-connect-python
or
pip3 install http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.zip
if the first one fails.
MySQLdb is the interface to MySQL database. As mentioned by other posts, MySQLdb doesn't support Python 3.x. I used PyMySQL as the replacement. You need to install it first:
pip install PyMySQL
The next step is to replace 'MySQLdb' with 'pymysql' in all the codes, which is intimidating. Luckily, PyMySQL can be loaded as MySQLdb dyanamically. In order to achieve it in Django, you need to add the following lines to __init__.py file under the dir of the project's default app (If your have a project named 'myproject', add lines to myproject/myproject/init.py):
import pymysql
pymysql.install_as_MySQLdb()
This __init__.py would be executed when you run the Django project, and MySQLdb will be replaced. You problem is then solved.
MySQLdb is not compatible with Python 3. Use mysql-client or mysql-connect.
You can use mysqlclient instead of MySQLdb. MySqLdb is not compatible with Python 3.
pip install mysqlclient