python mysqldb导入错误

时间:2012-07-11 12:59:08

标签: python ubuntu mysql-python

在ubuntu上我已经安装了mysql但仍然无法导入mysql数据库。以下是我遵循的步骤。任何人都可以指出我的解决方案 (其他信息是ubuntu安装在虚拟机上希望无所谓).Python版本是2.6.5

  root@rajeev-laptop:/opt/s/site# apt-get install python-mysqldb
  Reading package lists... Done
  Building dependency tree
  Reading state information... Done
  The following packages were automatically installed and are no longer required:
    linux-headers-2.6.32-21 linux-headers-2.6.32-21-generic
  Use 'apt-get autoremove' to remove them.
  Suggested packages:
    python-mysqldb-dbg
  The following NEW packages will be installed:
    python-mysqldb
  0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  Need to get 0B/76.6kB of archives.
  After this operation, 283kB of additional disk space will be used.
  Selecting previously deselected package python-mysqldb.
  (Reading database ... 151280 files and directories currently installed.)
  Unpacking python-mysqldb (from .../python-mysqldb_1.2.2-10build1_i386.deb) ...
  Setting up python-mysqldb (1.2.2-10build1) ...

  Processing triggers for python-support ...
  root@rajeev-laptop:/opt/s/site# python
  Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
  [GCC 4.4.3] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import MySQLdb
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  ImportError: No module named MySQLdb
  >>>

4 个答案:

答案 0 :(得分:1)

所有

我通过以下方式解决了这个问题,在我的/etc/bash.bashrc中,我将python路径导入为/ opt / s / django和我的网站都在哪里。当我从python路径中删除以下内容时导入MySQLdb工作。希望这篇文章能帮助某人..

答案 1 :(得分:0)

我会检查Python PATH并手动构建MySQLDB下载。从此源forge站点下载安装文件。

答案 2 :(得分:0)

包信息显示正在发生的事情(ubuntu 12.04):

apt-cache show python-mysqldb

[...]
Provides: python2.7-mysqldb
Depends: python2.7, [...]
Python-Version: 2.7
[...]

这个包适用于python 2.7 - 所以它没有安装2.6。在shell中执行python2.7并再次尝试导入。

(如果您有较旧的ubuntu版本,请在您的计算机上执行apt-cache命令以检查您的版本是否也是这种情况)

答案 3 :(得分:0)

啊,这些问题......在virtualenv为python投入了一些时间。它会得到回报=)

相关问题