Fix Python – ImportError: No module named MySQLdb


Asked By – user3182194

I am referring the following tutorial to make a login page for my web application.–net-29982

I am having issue with the database.
I am getting an

ImportError: No module named MySQLdb

when I execute

I have tried all possible ways to install python mysql, the one mentioned in the tutorial, easy_install, sudo apt-get install.

I have installed mysql in my virtual env. My directory structure is just the same as whats explained in the tutorial. The module is sucessfully installed in my system and still I am getting this error.

Please help. What could be causing this.

Now we will see solution for issue: ImportError: No module named MySQLdb


If you’re having issues compiling the binary extension, or on a platform where you cant, you can try using the pure python PyMySQL bindings.

Simply pip install pymysql and switch your SQLAlchemy URI to start like this:

SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://.....'

There are some other drivers you could also try.

This question is answered By – DazWorrall

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0