Django: how to install mysql/connector python with pip3

被刻印的时光 ゝ 提交于 2019-12-04 04:16:09

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

A mysqldb fork

There is a fork that supports Python 3. Read its Github repo to know how to install 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 modify your settings.py file to have it like:

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

Pay attention to the connector value mysql.connector.django :-)

The version of mysql-connector that pip installs doesn't work with Django 1.8. There is a fixed version on github. The command to install from there is

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

That one works with Django 1.8.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!