Django: how to install mysql / python connector with pip3

I am working on projects based on Django 1.7 and Python 3.4. However, I had problems installing MySQL / Connector Python with pip3.

According to this document , MySQL / Connector Python supports Python 3. I used MySQL-python to install MySQL-python in Python with the pip install MySQL-python command.

This download page contains only .deb files for installation on Ubuntu (by the way, the installation also has conflict issues )

I tried installing using:

 pip3 install mysql-connector-python --allow-external mysql-connector-python 

No error messages. But when I start the Django application, I received the following error message:

 django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb' 

Question: So, how to install MySQL / Connector Python in a virtual environment with pip3? Or should it be installed on the system instead of a virtual environment?

+6
source share
2 answers

If you read the documentation , you will see that the native MySQLdb driver does not support Python 3. You have two options:

Mysqldb fork

There is a fork that supports Python 3. Read its Github repository to learn how to install it with your system. For Ubuntu do apt-get install python-mysqldb

MySQL Connector

Install from venv, as you did with pip install mysql-connector-python --allow-external mysql-connector-python . Then read their documentation for Django and change your settings.py file so that it looks like:

 DATABASES = { 'default': { 'NAME': 'user_data', 'ENGINE': 'mysql.connector.django', 'USER': 'mysql_user', 'PASSWORD': 'priv4te', 'OPTIONS': { 'autocommit': True, }, } } 

Pay attention to the value of the mysql.connector.django connector mysql.connector.django

+10
source

The mysql connector version that pip installs does not work with Django 1.8. There is a fixed version on github. Command to install from there

 pip install --allow-all-external git+git://github.com/multiplay/mysql-connector-python 

This works with Django 1.8.

+4
source

Source: https://habr.com/ru/post/977238/


All Articles