安装
Django使用MySQL数据库需要加载 MySQLdb模块,需要安装 mysqlclient,若已经安装请略过。 (Django2.2版本之前我们安装的是pymysql模块,不过现在使用的mysqlclient )
pip install mysqlclient
如果安装错误,那么下载到本地去安装 执行命令查看python版本与系统位数(32/64位) C:\Users\Administrator>python Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
-
访问网址: mysqlclient -
下载一个对应的安装包当当前系统目录: Mysqlclient: a fork of the MySQL-python interface for the MySQL database. mysqlclient?1.4.6?pp373?pypy36_pp73?win32.whl mysqlclient?1.4.6?cp39?cp39?win_amd64.whl mysqlclient?1.4.6?cp39?cp39?win32.whl mysqlclient?1.4.6?cp38?cp38?win_amd64.whl ? mysqlclient?1.4.6?cp38?cp38?win32.whl mysqlclient?1.4.6?cp37?cp37m?win_amd64.whl mysqlclient?1.4.6?cp37?cp37m?win32.whl mysqlclient?1.4.6?cp36?cp36m?win_amd64.whl mysqlclient?1.4.6?cp36?cp36m?win32.whl mysqlclient?1.4.6?cp35?cp35m?win_amd64.whl mysqlclient?1.4.6?cp35?cp35m?win32.whl mysqlclient?1.4.6?cp27?cp27m?win_amd64.whl mysqlclient?1.4.6?cp27?cp27m?win32.whl 下载对应版本就行 -
执行安装: pip install mysqlclient?1.4.6?cp38?cp38?win32.whl
已安装情况下仍然报错
报错内容为找不到mysqlclient django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?
通常解决办法
- 项目(settings.py同级)目录中__init__.py中添加
import pymysql
pymysql.install_as_MySQLdb()
- 强制重装一下
pip install mysqlclient?1.4.6?cp38?cp38?win32.whl --force-reinstall
|