Forums

ImportError: No module named 'MySQLdb'

I opened a new python file named connectdb.py, and I imported mySQLdb. It raised the following error: "ImportError: No module named 'MySQLdb'". I read in https://www.pythonanywhere.com/forums/topic/1212/, that I in python 3, i have to isntall the module. But I don't understand how I do it, can you guide me? where and what I need to do?

I found out- In python 3.4 I need to write:

pip3.4 install --user https://github.com/davispuh/MySQL-for-Python-3/archive/1.0.tar.gz

cool!

                 / ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\    
    <<<<<<:>~  <   Yay!          |   
                 \_________/

Update: the recommended MySQL library for Python 3.x has now changed. If you're not using a virtualenv then you don't need to install anything -- it's already installed and you just need to import MySQLdb. If you are using a virtualenv, then start a bash console inside the virtualenv and run

pip install mysqlclient