导入MySQLdb不能在python中工作

时间:2014-09-16 04:38:27

标签: python mysql ubuntu mysql-python

我已执行以下命令安装mysqldb:

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 381 not upgraded.

但是当我尝试使用代码运行文件时:

import MySqldb;

通过

python index.py

它返回:

Traceback (most recent call last):
File "index.py", line 1, in <module>
import MySqldb;
ImportError: No module named MySqldb

请帮忙.. ??

1 个答案:

答案 0 :(得分:1)

该模块被称为MySQLdb - 观察案例:

import MySQLdb

演示:

>>> import MySqldb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named MySqldb
>>> import MySQLdb
>>> MySQLdb.__version__
'1.2.5'