错误场景
基于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()
在使用Python3.6和Django3.0的项目中,配置MySQL数据库时遇到mysqlclient兼容问题。错误提示需要mysqlclient 1.3.13或更新版本。官方建议在Linux环境下安装python3-dev, default-libmysqlclient-dev和build-essential等依赖库,然后通过pip安装mysqlclient。此外,还提供了Ubuntu/Debian和Red Hat/CentOS系统的具体安装命令。"
114817264,10538788,Java拖拽排序实现策略,"['Java开发', '数据排序', '后端设计']

438

被折叠的 条评论
为什么被折叠?



