django配置MySQL出错,python3.6+Django3.0 配置使用MySQL数据库错误 :mysqlclient 1.3.13 or newer is required...

错误场景

基于python3.6+Django3.0的项目配置MySQL时,安装pymysql的最高版本为0.9.3 ,为了导入MySQLdb时使用pymysql,在项目的__init__.py下添加以下代码:

import pymysql

pymysql.install_as_MySQLdb()

运行出现错误

django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

直接安装mysqlclient

pip install mysqlclient

报错

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

官方解释

PyMySQL的Github首页给出解释https://github.com/PyMySQL/mysqlclient-python

Linux

Note that this is a basic step. I can not support complete step for build for all environment. If you can see some error, you should fix it by yourself, or ask for support in some user forum. Don’t file a issue on the issue tracker.

You may need to install the Python 3 and MySQL development headers and libraries like so:

$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu

% sudo yum install python3-devel mysql-devel # Red Hat / CentOS

Then you can install mysqlclient via pip now:

$ pip install mysqlclient

解决办法

一、

Ubuntu / Debian:

sudo apt-get install python3-dev default-libmysqlclient-dev build-essential

# 如果是python3.7, 记得将python3-dev 改成 python3.7-dev

pip install mysqlclient

Red Hat / CentOS:

sudo yum install python3-devel mysql-devel

pip install mysqlclient

二、删除以下代码

import pymysql

pymysql.install_as_MySQLdb()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值