2016-04-19 39 views
-1

用於按照預期在Python 2.6中工作的Mysql.connector,但是因爲我想使用argparse,所以我安裝了2.7版本。在將連接器安裝到此版本時,我遇到了以下錯誤。我不知道如何解決它們。在從2.6遷移後在Python 2-7中安裝mysql.connector時出現問題

**Error while importing connector:** 

[/usr/local/bin ] # python 
Python 2.7.6 (default, Apr 19 2016, 19:36:47) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 
    Type "help", "copyright", "credits" or "license" for more information. 
    >>> import mysql.connector 
    Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    ImportError: No module named mysql.connector 
    >>> 

**Paths located** 

[~ ] # which python2.6 
/usr/bin/python2.6 
[~ ] # which python2.7 
/usr/local/bin/python2.7 
[~ ] # which python 
/usr/local/bin/python 
[~ ] # ls -l /usr/local/bin/py* 
-rwxr-xr-x 1 root root  84 Apr 19 18:10 /usr/local/bin/pydoc 
lrwxrwxrwx 1 root root  18 Apr 19 21:57 /usr/local/bin/python ->  /usr/bin/python2.6 
lrwxrwxrwx 1 root root  9 Apr 19 18:10 /usr/local/bin/python2 -> python2.7 
-rwxr-xr-x 1 root root 6214541 Apr 19 19:36 /usr/local/bin/python2.7 
-rwxr-xr-x 1 root root 1674 Apr 19 19:36 /usr/local/bin/python2.7-config 
lrwxrwxrwx 1 root root  16 Apr 19 18:10 /usr/local/bin/python2-config ->  python2.7-config 
lrwxrwxrwx 1 root root  14 Apr 19 18:10 /usr/local/bin/python-config -> python2-config 
[~ ] # pip -V 
pip 7.1.0 from /usr/lib/python2.6/site-packages (python 2.6) 

**Trying to install mysql connector for python 2.7** 

    [/usr/src ] # rpm -i mysql-connector-python-2.0.4-1.el7.noarch.rpm 
    error: Failed dependencies: 
    python(abi) = 2.7 is needed by mysql-connector-python-2.0.4-1.el7.noarch 

回答

0

我會建議使用安裝與pip相同版本的Python您使用在你試圖做import mysql.connector的REPL的mysql-connector-python包。因此,如果您嘗試安裝mysql-connector-python,請嘗試使用pip2.7進行安裝,它應與機器上的python2.7二進制文件位於同一目錄中。

-1

一個簡單而不優雅的方法是安裝較舊版本的連接器。 與我的情況一樣,mysql-connector-python-1.2.3-1 ...... rpm安裝在類似的環境中。

BTW,檢查是轉-q蟒蛇,那麼你會發現該系統最初是與python2.6的安裝: 蟒蛇-2.6.8-0.15.1

的python2.7安裝以後不會更改系統信息。