2015-12-14 36 views
1

我的Ubuntu 10.04附帶了Python 2.6。現在,我還安裝了Python 2.7,這是現在的系統默認值,因爲當我從終端啓動python時,它會啓動python 2.7。通過pip安裝pysftp失敗(因爲有2個python2.x版本)

現在,我想使用pip安裝庫pysftp,但我很難做到這一點。以下是我的嘗試和結論的一些結果。我做了pip install pysftp,但它說以下內容:

Downloading/unpacking pysftp 
    Running setup.py egg_info for package pysftp 
    Traceback (most recent call last): 
     File "<string>", line 3, in <module> 
     File "/usr/local/lib/python2.6/dist-packages/setuptools/__init__.py", line 12, in <module> 
     from setuptools.extension import Extension 
     File "/usr/local/lib/python2.6/dist-packages/setuptools/extension.py", line 8, in <module> 
     from .dist import _get_unpatched 
     File "/usr/local/lib/python2.6/dist-packages/setuptools/dist.py", line 21, in <module> 
     packaging = pkg_resources.packaging 
    AttributeError: 'module' object has no attribute 'packaging' 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 

    File "<string>", line 3, in <module> 

    File "/usr/local/lib/python2.6/dist-packages/setuptools/__init__.py", line 12, in <module> 

    from setuptools.extension import Extension 

    File "/usr/local/lib/python2.6/dist-packages/setuptools/extension.py", line 8, in <module> 

    from .dist import _get_unpatched 

    File "/usr/local/lib/python2.6/dist-packages/setuptools/dist.py", line 21, in <module> 

    packaging = pkg_resources.packaging 

AttributeError: 'module' object has no attribute 'packaging' 

---------------------------------------- 
Command python setup.py egg_info failed with error code 1 
Storing complete log in ./pip-log.txt 

在我看來,(安裝的Python 2.7之前明明安裝了),那點子鏈接到舊版本的Python,不支持pysftp。此外,因爲當我做pip --version它說:

pip 0.3.1 from /usr/lib/python2.6/dist-packages (python 2.6) 

當我做whereis python,它給我的以下信息:

python: /usr/src/Python-2.7.10/python /usr/bin/python2.6 /usr/bin/python /etc/python2.6 /etc/python /usr/lib/python2.6 /usr/lib/python3.1 /usr/lib64/python2.6 /usr/lib64/python3.1 /usr/local/bin/python2.7-config /usr/local/bin/python /usr/local/bin/python2.7 /usr/local/lib/python2.6 /usr/local/lib/python2.7 /usr/include/python2.6 /usr/share/python /usr/share/man/man1/python.1.gz 

如何安裝pysftp?

回答

0

您需要爲Python 2.7重新安裝pip,然後運行pip2.7 install pysftp。您需要爲每個要使用的Python版本安裝pipsetuptools包可能是最簡單的方法;你可以簡單地運行下面做這一切一舉:

wget https://bootstrap.pypa.io/ez_setup.py -O --no-check-certificate - | sudo python2.7 && sudo easy_install-2.7 pip && sudo pip2.7 install pysftp 

有時,老版本的Linux安裝有問題與上面的命令,由於「無效」證書中遇到,同時通過ez_setup.py下載完整setuptools包( see here瞭解更多詳情)。這可以通過這種替代一下子的命令來避開:

wget https://pypi.python.org/packages/source/s/setuptools/setuptools-18.8.1.zip --no-check-certificate && unzip setuptools-18.8.1.zip && cd setuptools-18.8.1 && sudo python setup.py install && sudo easy_install-2.7 pip && sudo pip2.7 install pysftp 
+0

我得到了wget命令的證書錯誤(用'--no-check-certificate'解決)。然後腳本給出'返回狀態5'(同時爲setuptools調用wget)。手動下載該文件後,它會顯示「zipfile.BadZipfile:文件不是zip文件」。幫幫我? – Lewistrick

+0

@Lewistrick這是不尋常的,我無法想象爲什麼它會試圖解壓縮一些東西......它在'sudo python2.7 ez_setup.py'部分失敗了? – Mego

+0

是的,它試圖解壓本地版本的https:// pypi.python.org/packages/source/s/setuptools/setuptools-18.8.1.zip。它使用了錯誤的文件嗎? – Lewistrick