错误场景 基于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-devpip install mysqlclient
Red Hat / CentOS:
sudo yum install python3-devel mysql-develpip install mysqlclient
【#|python3.6+Django3.0 配置使用MySQL数据库错误 (mysqlclient 1.3.13 or newer is required)】二、删除以下代码
import pymysql
pymysql.install_as_MySQLdb()
推荐阅读
- 数据结构和算法|LeetCode 的正确使用方式
- #|7.分布式事务管理
- #|算法设计与分析(Java实现)——贪心算法(集合覆盖案例)
- #|算法设计与分析(Java实现)—— 动态规划 (0-1 背包问题)
- #|阿尔法点亮LED灯(一)汇编语言
- #|Multimedia
- #|ARM裸机开发(汇编LED灯实验(I.MX6UL芯片))
- 基础课|使用深度优先搜索(DFS)、广度优先搜索(BFS)、A* 搜索算法求解 (n^2 -1) 数码难题,耗时与内存占用(时空复杂度)对比(附((n^2 - 1) 数码问题控
- #|学习笔记 | Ch05 Pandas数据清洗 —— 缺失值、重复值、异常值
- win10|搏一搏 单车变摩托,是时候捣鼓一下家中的小米电视机啦。