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
mysqlclient
EDIT: Wanted to add that I have also deleted the pip cache and it still does not work.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With