Install MySQLclient using pip

Posted under » MySQL » Python » Django on 06 April 2021

Unlike LAMP which automatically setup MySQL connection to PHP, Python connection to MySQL can be tricky.

To install, follow this instruction or continue reading.

$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential

Note that if you have a specifc version of Python, eg. 3.8 you have to specify it.

$ sudo apt-get install python3.8-dev default-libmysqlclient-dev build-essential

Once installed, then run Pip in your environment. Pip is a package-management system written in Python used to install and manage software packages. It connects to an online repository of public and paid-for private packages, called the Python Package Index. Most distributions of Python come with pip pre-installed. Check by

$ pip --version 

But if not, then

$ sudo apt install python3-pip
$ sudo apt install python3.8-pip # or

Don't install mysqlclient first until you install wheel or else you will get error when in venv.

$ pip install -U wheel

After installing PIP do not use sudo pip or it will break apps.

Afterwhich you can proceed installing mysqlclient

$ pip install mysqlclient

If you want to uninstall.

$ pip uninstall mysqlclient

If you want to see the list of installed libraries

$ pip list

Find using Python Package Index.

See also Connect MySQL with pymysql.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS IOT