1

I'm failing at importing MySQLdb: import MySQLdb results in:

ModuleNotFoundError: No module named 'MySQLdb'

I installed the following:

  1. pip install mysql-python
  2. pip install mysqlclient
  3. apt-get install python3-dev python-pip python-dev libmysqlclient-dev
  4. apt-get install python-mysqldb (which according to this should suffice)

Here is my pip freeze | grep -i sql:

  • mysqlclient==1.3.13
  • MySQL-python==1.2.5

I'm using Python 3.6 with PyCharm Community Edition on a virtual machine Ubuntu 18.04

What is missing here in order to use this? (also, is there another recommended module for Python API into mysql?)


Although this states there is no MySQLdb for Python3.X, this (and this) show it is alive and kicking, I think...

3
  • 1
    You should use pip3 instead of pip
    – Mufeed
    Commented Jul 9, 2018 at 12:31
  • @Mufeed Thanks! that was it (In the meantime I switched to Python 2 and it worked there). Would you like to answer so I could accept? Commented Jul 9, 2018 at 12:44
  • I added the answer.
    – Mufeed
    Commented Jul 9, 2018 at 12:49

1 Answer 1

3

You should use pip3 instead of pip, since you are using Python 3.6.
Use pip for Python2.x
So your command should be like

pip3 install mysqlclient
4
  • actually pip3 install mysql-python gave an error. The pip3 install mysqlclient worked and solved the issue Commented Jul 9, 2018 at 12:50
  • Okay. I added it as an example.
    – Mufeed
    Commented Jul 9, 2018 at 12:51
  • 1
    it is better to use python3 -m pip install ... i.e. explicitly specify which Python version to use Commented Jul 9, 2018 at 15:34
  • I believe they both are equivalent.
    – Mufeed
    Commented Jul 10, 2018 at 4:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.