import MySQLdb as Database ModuleNotFoundError: No module named ‘MySQLdb‘
import MySQLdb as Database ModuleNotFoundError: No module named ‘MySQLdb‘
import MySQLdb as Database ModuleNotFoundError: No module named 'MySQLdb'
[root@bbs s12bbs]# python3 manage.py --help
Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 25, in <module>
import MySQLdb as Database
ImportError: No module named ‘MySQLdb'
解决:
vim /usr/lib/python3.4/site-packages/django/db/backends/mysql/base.py
#导入
#在from django.utils.safestring import SafeBytest,SafeTest下添加下面两条
import pymysql
pymysql.install_as_MySQLdb()
方法解析:
MySQLdb只支持Python2.,还不支持3.
可以用PyMySQL代替。安装方法:
pip install PyMySQL
然后在需要的项目中,把 init.py中添加两行:
import pymysql
pymysql.install_as_MySQLdb()
就可以用 import MySQLdb了。其他的方法与MySQLdb一样。