Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip says it installs mysqlclient successfully, but cannot find it or uninstall it

I am running into the following issue trying to install mysqlclient as part of getting a Django project up and running on an AWS EC2 instance.

In a python 3.8.5 virtual environment:

(venv3)$ which pip
~/venv3/bin/pip

(venv3)$ pip --version
pip 21.0.1 from /home/ec2-user/venv3/local/lib/python3.8/dist-packages/pip (python 3.8)

(venv3)$ pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.0.3-cp38-cp38-linux_x86_64.whl
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.0.3

I try running the Django Shell:

(venv3)$ python manage.py shell
...full trace stack truncated for brevity...
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

So I tried to find where pip installed it, and it seems to not actually be installed or be a trace of it anywhere:

(venv3)$ pip show mysqlclient
WARNING: Package(s) not found: mysqlclient

(venv3)$ pip freeze | grep -i mysqlclient
<nothing>

(venv3)$ sudo find / -name mysqlclient
<nothing>

Then as a sanity check I apparently successfully install it but then pip can't find it to uninstall it:

(venv3)$ pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.0.3-cp38-cp38-linux_x86_64.whl
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.0.3

(venv3)$ pip uninstall mysqlclient
WARNING: Package(s) not found: mysqlclient

Other things I have tried/verified

  • Making sure python is the 64-bit version
  • Checking pip outside of the virtual environment
  • Nuking the virtual environment and starting again
  • Trying to install specific versions of mysqlclient
  • Installing and importing/using any other python package

EDIT: Wanted to add that I have also deleted the pip cache and it still does not work.

like image 823
liamhawkins Avatar asked Aug 30 '25 17:08

liamhawkins


1 Answers

Answering my own question because I finally figured it out.

As per @user202729's comment I ran pip in verbose mode pip install mysqlclient --verbose which didn't itself show anything out of the ordinary as far as I could tell, but did show that mysqlclient and MySQLdb related files were being installed in /dist-packages which was not being picked my by my python installation. I copied the MySQLdb directory from venv3/lib64/python3.8/dist-packages to venv3/lib64/python3.8/site-packages and that solved the python and django issues.

like image 51
liamhawkins Avatar answered Sep 02 '25 08:09

liamhawkins