我做了很多研究,但找不到任何解决方案 我一直收到这个错误:
Traceback (most recent call last):
File "test.py", line 2, in <module>
import MySQLdb
ImportError: No module named 'MySQLdb'
我也安装了这个:并且得到了这个。
yesh@Yesh:~/DBMS$ sudo apt-get install python-mysqldb
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-mysqldb is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
有人请帮帮我。我想这与环境变量有关。我不确切知道那是什么。提前致谢
答案 0 :(得分:1)
首先确保安装了python mysql驱动程序:
sudo pip install pymysql
将此添加到settings.py:
# For PyMySQL
try:
import pymysql
pymysql.install_as_MySQLdb()
except ImportError:
pass
您可以尝试以下方法测试它的工作原理:
$ ipython
import MySQLdb #Confirm you get an error
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb #No error