0,环境信息
我使用的是centos7.6 ,python3 = 3.6.8 下的虚拟环境
rpm -qa |grep MySQL
MySQL-client-5.7.25-1.el7.x86_64
MySQL-shared-5.7.25-1.el7.x86_64
MySQL-server-5.7.25-1.el7.x86_64MySQL-devel-5.7.25-1.el7.x86_64
MySQL-config-5.7.25-1.el7.x86_64
1, 报错
File "/home/osaas_sap/venv3/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 21, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install MySQLdb?
2,解决办法
- 我首先检查了我的MySQL的rpm包是否齐全,不要漏了 MySQL-devel-5.7.25-1.el7.x86_64
- 安装 pymysql
venv/bin/pip install pymysql- 安装好之后还会报错,
django.core.exceptions.ImproperlyConfigured: pymysql 1.3.13 or newer is required; you have 1.3.12.
则 还需要修改 一些django backends 的代码
/venv3/lib/python3.6/site-packages/django/db/backends/mysql/base.py ; 改成1.3.12- 应该就已经解决了
3, 效果图