问题1: 无法安装mysqlclient
报错信息:
解决方法:
1. 安装mysql-client
brew install mysql-client
2、配置环境变量
vi ~/.bash_profile export PATH=/opt/homebrew/opt/mysql-client/bin:$PATH source ~/.bash_profile
3、安装mysqlclient
pip install mysqlclient
4. 如果还是无法安装,请退出虚拟环境重新进入试一下
参考博文:https://www.jianshu.com/p/0b565b66d7d5
问题2: 运行django时报错:NameError: name '_mysql' is not defined
报错信息:
解决方法:
在__init__.py文件里写入
import pymysql pymysql.install_as_MySQLdb()
重新执行后报错:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.3 or newer is required; you have 1.0.2.
解决方法:
在__init__.py文件里写入
import pymysql pymysql.version_info = (1, 4, 13, 'final', 0) pymysql.install_as_MySQLdb()
参考博文:https://blog.csdn.net/weixin_42161670/article/details/118639385
问题3: 报错:django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.7.39).
报错信息:
解决方法:
vi /usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py
搜索“self.check_database_version_supported”,然后把这一行注释掉。
参考博文:https://blog.bccn.net/%E9%9D%99%E5%A4%9C%E6%80%9D/68210
标签:python,mysqlclient,pymysql,django,mac,报错,install,mysql From: https://www.cnblogs.com/jay-/p/17298763.html