码迷,mamicode.com
首页 > 数据库 > 详细

Django 错误之 No module named ‘MySQLdb’

时间:2019-01-07 17:40:20      阅读:616      评论:0      收藏:0      [点我收藏+]

标签:pack   mysq   configure   usr   3.x   conf   for   解决办法   适用于   


报错如下:
File "/usr/local/python3/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 27, in <module>

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named ‘MySQLdb‘


MySQLdb 只适用于python2.x,。在python3.x的替代品是: import pymysql

解决办法:

vi /usr/local/python3/lib/python3.4/site-packages/django/db/backends/mysql/__init__.py

base.py 文件新增如下两行:
import pymysql
pymysql.install_as_MySQLdb()

 

如果还报如下错误:
AttributeError: module ‘pymysql‘ has no attribute ‘install_as_MySQLdb‘

解决方法:
pip uninstall PyMySQL3
pip install -U --force-reinstall pymysql

Django 错误之 No module named ‘MySQLdb’

标签:pack   mysq   configure   usr   3.x   conf   for   解决办法   适用于   

原文地址:https://www.cnblogs.com/liang545621/p/10233857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!