【发布时间】:2014-07-29 18:34:00
【问题描述】:
我已经安装了一个 python 库 MySQLdb,它昨天工作。但是今天当我尝试运行它时,它继续如下:
czhao@opx790:~$ python
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 2 2014, 12:34:02)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
真的很奇怪,所以我尝试重新安装它,但我的计算机中似乎确实有该库:
czhao@opx790:~$ sudo apt-get install python-mysqldb
[sudo] password for czhao:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-mysqldb is already the newest version.
The following packages were automatically installed and are no longer required:
libgooglepinyin0-dev linux-headers-3.2.0-27 linux-headers-3.2.0-41
linux-headers-3.2.0-37 linux-headers-3.2.0-43 linux-headers-3.2.0-61
patchutils linux-headers-3.2.0-37-generic linux-headers-3.2.0-27-generic
linux-headers-3.2.0-61-generic linux-headers-3.2.0-43-generic dpatch
linux-headers-3.2.0-41-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.
我不知道为什么,我有这个库,但是 python 一直告诉我我没有。
【问题讨论】:
-
你试过
sudo apt-get purge python-mysqldb; sudo apt-get install python-mysqldb吗? -
尝试使用 pip 安装,
pip install MySQL-python -
既然你在使用 Anaconda,你应该看看这个帖子:stackoverflow.com/questions/19150416/…