1

I've been bugging on this task for a while now, and I've found a lot posts addressing this problem but none seemed recent enough to help me (A lot of posts about python 2.7, and the few ones about python3 weren't using MySQL)

I am using Django 1.9, Python 3.4.2, WSGI 3.4.4 and MySQLClient 1.3.7

At first, I had this error in my apache logs :

ImproperlyConfigured: Error loading MySQLdb module: No module named _mysql

It is my understanding that MySql-Python does not work on python3 and that this is the command to install the recommanded adapter:

sudo apt-get install python-mysqldb

But when I install this adapter, I get this error from apache logs :

ImproperlyConfigured: Error loading MySQLdb module: this is MySQLdb version (1, 3, 7, 'final', 1), but _mysql is version (1, 2, 3, 'final', 0)

By the way, I've also installed and updated mysqlclient with pip3, but it doesn't look like its doing anything, as I still had the "No module named _mysql" error after installing it. Am I misunderstanding something or is this just really a compatibility problem with Python3?

How can I install the compatible MySQL adapter?

Thank you.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
Blopblop
  • 11
  • 3
  • Possible duplicate of [How do I install and use MySQLdb for Python 3 on Windows 10?](http://stackoverflow.com/questions/34836570/how-do-i-install-and-use-mysqldb-for-python-3-on-windows-10) – Rahul Parida Feb 23 '17 at 20:12

1 Answers1

3

You are correct that MySql-Python does not work with Python 3. The recommened adapter for Django with MySQL and Python 3 is mysqlclient. Your command apt-get install python-mysqldb is installing the MySql-Python package for Python 2, which isn't very helpful here.

You can install mysqlclient with pip. On Ubuntu, you should first install libmysqlclient-dev python3-dev

apt-get install libmysqlclient-dev python3-dev

Then, enter your virtual environment. Now you caninstall mysqlclient using pip.

pip install mysqlclient

If you are not using virtualenv (it's recommended that you do), then you can use pip3 to install it globally for Python 3.

pip3 install mysqlclient
Alasdair
  • 298,606
  • 55
  • 578
  • 516