【问题标题】:Why I can not use an installed module for python?为什么我不能为 python 使用已安装的模块?
【发布时间】: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/…

标签: python mysql linux


【解决方案1】:

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

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

【讨论】:

  • 它是pip install MySQL-python
猜你喜欢
  • 2022-12-18
  • 1970-01-01
  • 2023-01-27
  • 2023-04-01
  • 2021-04-26
  • 2012-07-05
  • 1970-01-01
  • 2013-08-04
  • 2014-10-22
相关资源
最近更新 更多