9

I used

python3 -m pip install mysqlclient

and it installed successfully.

However when I try to import this into my python code using

import mysqlclient as sql

It comes up with

ImportError: No module named 'mysqlclient'

What am I doing wrong that doesn't allow me to import this module.

Sho.Y
  • 353
  • 1
  • 3
  • 6

2 Answers2

26

Turns out its

import MySQLdb

I was previously using

import mysqldb 

which didnt work

Sho.Y
  • 353
  • 1
  • 3
  • 6
3

If you are getting an error, then probably the package is not installed properly ! Here are some alternatives to install mysqlclient

Install from source

Download source by git clone or zipfile.

Customize site.cfg

python setup.py install

Note: The above method is little complex for beginners.

You can visit this site for Python3.5 and Python3.6 and download the .whl package.

Next step is to install the .whl package, (for example) if you have Python3.5, you can :

pip install mysqlclient-1.3.10-cp35-cp35m-win32.whl

And use,

import MySQLdb as sql to import the module.

Hope it helps !

0x48piraj
  • 395
  • 3
  • 12