Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import mysqlclient in python3 [duplicate]

Tags:

python

mysql

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.

like image 520
Sho.Y Avatar asked Jul 16 '17 05:07

Sho.Y


People also ask

Does Mysqlclient support Python 3?

This project is a fork of MySQLdb1. This project adds Python 3 support and fixed many bugs.


2 Answers

Turns out its

import MySQLdb

I was previously using

import mysqldb 

which didnt work

like image 107
Sho.Y Avatar answered Sep 25 '22 08:09

Sho.Y


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 !

like image 45
0x48piraj Avatar answered Sep 22 '22 08:09

0x48piraj