2012-07-11 136 views
1

在Ubuntu上我已經安裝了mysql,但仍然無法導入mysql數據庫。下面是我followed.Can任何一個點我解決這個 (其他信息是Ubuntu的安裝在一個虛擬的盒子,希望不應該的問題).Python版本的步驟是2.6.5python mysqldb導入錯誤

[email protected]:/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 ... 
    [email protected]:/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 
    >>> 

回答

0

啊這些問題...投資一些時間在python的virtualenv。它會回報=)

0

我將檢查Python PATH並手動構建MySQLDB下載。從此源代碼站點下載安裝文件。

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命令來檢查,如果這是在您的版本的情況下也一樣)

+0

提供:python2.6-mysqldb 取決於:python(<< 2.7),python(> = 2.6),python-support(> = 0.90.0),libc6(> = 2.4) ,libmysqlclient16(> = 5.1.21-1) – Rajeev 2012-07-11 14:57:37

+0

我有Ubuntu 10.04 – Rajeev 2012-07-11 15:00:28

1

所有,

我得到這個由解決下面,在我的/etc/bash.bashrc中,我導入了一個Python路徑,名稱爲/ opt/s/ django和我的網站在哪裏。當我從pythonpath中刪除以下內容時,導入MySQLdb正常工作..希望這篇文章能夠幫助某人..