在centos部署python应用后访问页面,显示如下异常信息

报错环境 python=3.6,django=2.2
……
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
解决方法:
Django连接MySQL时默认使用MySQLdb驱动,但MySQLdb不支持Python3,因此这里将MySQL驱动设置为pymysql,使用 pip install pymysql 进行安装,然后在工程文件__init__.py添加以下代码即可。

#安装pymysql
pip install pymysql
#__init__.py
import pymysql
pymysql.install_as_MySQLdb()

第一种:
django降到2.1.4版本就OK了

第二种(仍使用django 2.2版本):

#找到Python环境下 django包,并进入到backends下的mysql文件夹
cd /opt/anaconda3/envs/envAGC_Mini/lib/python3.6/site-packages/django/db/backends/mysql
#文件列表如下

 # 找到base.py文件,注释掉 base.py 中如下部分(35/36行)
if version < (1, 3, 3):
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)

此时仍会会报错,报错信息如下:

AttributeError: ‘str’ object has no attribute ‘decode’

 #找到operations.py文件(46行,版本不同行数不同哈~自个儿find一下),将decode改为encode
#linux vim 查找快捷键:?decode
if query is not None:
query = query.decode(errors='replace')
return query
#改为
if query is not None:
query = query.encode(errors='replace')
return query

修改保存之后,不再报错。

原文

exceptions: django2.2/ mysql ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3的更多相关文章

  1. django2.2/mysql ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3

      报错环境 python=3.6.5,django=2.2,PyMySQL=0.9.3 …… django.core.exceptions.ImproperlyConfigured: mysqlcl ...

  2. Django项目配置数据库时,已安装mysqlclient,却提示 Did you install mysqlclient错误,后右报错ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3

    错误信息如下: 解决方案是: 找到自己的项目文件夹下的__init__.py  添加如下代码 解决这个问题后,右报错django2.2/mysql ImproperlyConfigured: mysq ...

  3. Django2.2报错 django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

    准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: django.core.exceptions.Improperly ...

  4. django.db.migrations.exceptions.MigrationSchemaMissing和raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

    1.使用Python3.7 + Django2.2 + MySQL 5.5 在执行(python manage.py migrate)命令时出现错误django.db.migrations.excep ...

  5. django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.2的最佳处理方法,亲测可用

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

  6. django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.解决办法

    "E:\API_Manager_PlatForm\venv\lib\site-packages\django\db\backends\mysql\base.py"在这个路径里件把b ...

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

    异常汇总:https://www.cnblogs.com/dotnetcrazy/p/9192089.html 这个是Django对MySQLdb版本的限制,我们使用的是PyMySQL,所以不用管它 ...

  8. Django生成脚本迁移文件时,报错django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

    一.本人环境:django:3.0.2, python:3.8.1,  pymysql:0.9.3 二.解决步骤: 1.django目录下找到 base.py文件: 2.在base.py文件中注释以下 ...

  9. 报错: raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

    Django2.0同步Mysql数据库时出现的问题 执行 python manage.py makemigrations 报错 # 报错位置 File "G:\python\lib\site ...

随机推荐

  1. grep 查找文件

    --递归查找目录下含有该字符串的所有文件 grep -rn "data_chushou_pay_info" /home/hadoop/nisj/automationDemand/ ...

  2. mongodb 在 linux 中的安装和简单使用

    一.环境介绍 1.mongodb版本: mongodb-linux-x86_64-rhel70-3.2.22  # 点击下载2.linux版本: Ubuntu 18.04.2 LTS 二.安装1.上传 ...

  3. bzoj3631: [JLOI2014]松鼠的新家(树上差分)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3631 题目大意:给定含有n个顶点的树,给定走遍整棵树顺序的序列a[1],a[2],a[3 ...

  4. const定义的并非是常量,而是常量索引

    我第一次看const的时候,记忆中对const的定义是,定义常量. 后经过研究,定义的并非常量,而是常量索引. 有时候会遇到使用const定义数组的情况 const arr = [] arr.push ...

  5. git初始化第一次拉取线上操作

    git: 所有的filename都代表文件名称 一次:git clone 地址    第一步:更新 git pull   第二步:查看修改状态 git status   第三步:根据修改状态查看需要添 ...

  6. java Thread源码分析

    一.使用 java 多线程 java多线程其中两种使用方式: 1.继承 Thread 类 2.实现 Runnable 接口 public class ThreadTest { public stati ...

  7. Tengine + Lua + GraphicsMagick 实现图片自动裁剪/缩放

    http://my.oschina.net/eduosi/blog/169606

  8. mongdb 学习

    一:安装1.首先到官网(http://www.mongodb.org/downloads )下载合适的安装包2.安装mongodb3. cmd 命令切换到安装目录bin 下面 mongod --dbp ...

  9. 关于ADM和高维空间下距离度量的问题

    最近聆听了两个IEEE FELLOW的高论.周末北大林老师来学校做了个报告,讲了很多新的机器学习概念.但是本人更关注的低秩学习,林老师只字未提.虽然如此,林老师的论文最近还是深入研究了很多,有多少改进 ...

  10. vue-cli3.0配置

    仅在项目根目录中新建vue.config.js文件即可,部分配置如下 module.exports = { // 基本路径 baseUrl: '/', // 输出文件目录 outputDir: 'di ...