我已经安装了一个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一直告诉我,我没有它。
答案 0 :(得分:0)
您正在使用Anaconda Python,但是为系统Python安装了随apt-get
安装的软件包。这两个不同的发行版具有不同的库目录,因此安装了一个的软件包/模块不可用于另一个。
要解决此问题,请使用Anaconda附带的pip
程序并运行sudo pip install MySQL-python
。