Django:如何使用pip3安装mysql/connector python [英] Django: how to install mysql/connector python with pip3

查看:237
本文介绍了Django:如何使用pip3安装mysql/connector python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于Django 1.7和Python 3.4的项目上工作.但是,我在通过pip3安装MySQL/Connector Python时遇到问题.

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

根据此文档,MySQL/Connector Python支持Python 3.我曾经使用命令pip install MySQL-python在Python中安装MySQL-python.

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

此下载页面仅提供.deb文件以在Ubuntu上安装(btw,安装也有冲突问题)

This download page only provides .deb files for installation on Ubuntu (btw, the installation also has conflict problems)

我尝试安装:

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

无错误消息.但是当我运行Django应用程序时,出现以下错误消息:

No error messages. But when I run the Django app, I got the following error message:

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

问题: 那么,如何使用pip3将MySQL/Connector Python安装到虚拟环境中?还是应该将其安装到系统中,而不是虚拟环境中?

Question: So, how do I install MySQL/Connector Python into a virtual environment with pip3? Or is it supposed to be installed into the system, instead of a virtual environment?

推荐答案

如果您阅读原生MySQLdb驱动程序没有不支持Python3.您有两种选择:

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

一个mysqldb fork

有一个支持Python 3的叉子.请阅读其Github存储库以了解如何安装你的系统.对于Ubuntu,请apt-get install python-mysqldb

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连接器

像使用pip install mysql-connector-python --allow-external mysql-connector-python一样从venv安装.然后阅读其有关Django的文档,并修改您的settings.py文件具有以下特征:

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,
        },
    }
}

请注意连接器值mysql.connector.django:-)

这篇关于Django:如何使用pip3安装mysql/connector python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆