Error While Installing mysqlclient in virtualenv

Error While Installing mysqlclient in virtualenv

While trying to connect MySQL database with Django 3.2 in my Ubuntu 18.04, I encounted this error.  I was not able to pip install mysqlclient in my virtualenv. This short tutorial is about how to fix this issue.

If your MySQL setup is running perfect and you are unable to install mysqlclient in virtualenv then first check if there is no installation error outside the environment. If mysqlclient shows no issue then try with the solution below else try to reinstall MySQL again. To check if MySQL is running properly:

 mysql -u root -p

in terminal. I am running virtualenv in python 3.9. The easiest way to fix this error is by:

sudo apt-get install python-dev python3.9-dev
sudo apt-get install libmysqlclient-dev
pip install pymysql
pip install mysqlclient

NOTE: Change python3.X-dev version according to your environment python version.

Leave a Reply

Your email address will not be published. Required fields are marked *