为什么我不能使用已安装的模块进行python?(Why I can not use an installed module for python?)

我已经安装了一个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一直告诉我,我没有它。

I have installed a python library MySQLdb, and it works yesterday. But today when I tried to run it, it goes on as following:

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

It is really strange, so I try to re-install it, but it seems I do have the library in my computer:

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.

I do not know why, I have the library but python keep tell me I do not have it.

最满意答案

您正在使用Anaconda Python,但是为系统Python安装了随apt-get安装的软件包。 这两个不同的发行版具有不同的库目录,因此安装了一个的软件包/模块不可用于另一个。

要解决这个问题,请使用Anaconda附带的pip程序并运行sudo pip install MySQL-python 。

You are using Anaconda Python, but the package installed with apt-get was installed for the system Python. These two different distributions have different library directories, so packages/modules installed with one are not available for the other.

To get around this, use the pip program that came with Anaconda and run sudo pip install MySQL-python.

为什么我不能使用已安装的模块进行python?(Why I can not use an installed module for python?)

我已经安装了一个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一直告诉我,我没有它。

I have installed a python library MySQLdb, and it works yesterday. But today when I tried to run it, it goes on as following:

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

It is really strange, so I try to re-install it, but it seems I do have the library in my computer:

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.

I do not know why, I have the library but python keep tell me I do not have it.

最满意答案

您正在使用Anaconda Python,但是为系统Python安装了随apt-get安装的软件包。 这两个不同的发行版具有不同的库目录,因此安装了一个的软件包/模块不可用于另一个。

要解决这个问题,请使用Anaconda附带的pip程序并运行sudo pip install MySQL-python 。

You are using Anaconda Python, but the package installed with apt-get was installed for the system Python. These two different distributions have different library directories, so packages/modules installed with one are not available for the other.

To get around this, use the pip program that came with Anaconda and run sudo pip install MySQL-python.