2015-02-11 67 views
5

我已經在我的Mac上安裝了使用Homebrew的Python 2.7.9,並且Homebrew也安裝了點子。還有一個較舊的未使用版本的Python,默認安裝在我的Mac上。在自制Python 2.7安裝中升級點的問題

問題是,當我嘗試升級pip(使用pip install --upgrade pip)時,pip似乎想升級Python的舊版默認版本附帶的pip版本。這裏會發生什麼(在做一個新安裝Python 2.7.9,即brew remove python其次brew install python後):以上

$ pip -V 
pip 6.0.7 from /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg (python 2.7) 

似乎是正確的。但是,會發生以下情況:

$ pip install --upgrade pip 
You are using pip version 6.0.7, however version 6.0.8 is available. 
You should consider upgrading via the 'pip install --upgrade pip' command. 
Collecting pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-6.0.8-py2.py3-none-any.whl#md5=41e73fae2c86ba2270ff51c1d86f7e09 
    Using cached pip-6.0.8-py2.py3-none-any.whl 
Installing collected packages: pip 
    Found existing installation: pip 6.0.7 
    Uninstalling pip-6.0.7: 
     Successfully uninstalled pip-6.0.7 

Successfully installed pip-1.4.1 

爲什麼安裝了pip 1.4.1?現在我得到:

$ pip -V 
pip 1.4.1 from /Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg (python 2.7) 

這似乎對應於較舊的默認版本的Python。當我嘗試再次升級,它失敗:

$ pip install --upgrade pip 
Downloading/unpacking pip from https://pypi.python.org/packages/source/p/pip/pip-6.0.8.tar.gz#md5=2332e6f97e75ded3bddde0ced01dbda3 
    Downloading pip-6.0.8.tar.gz (1.2MB): 1.2MB downloaded 
    Running setup.py egg_info for package pip 

    warning: no previously-included files found matching '.coveragerc' 
    warning: no previously-included files found matching '.mailmap' 
    warning: no previously-included files found matching '.travis.yml' 
    warning: no previously-included files found matching 'pip/_vendor/Makefile' 
    warning: no previously-included files found matching 'tox.ini' 
    warning: no previously-included files found matching 'dev-requirements.txt' 
    no previously-included directories found matching '.travis' 
    no previously-included directories found matching 'docs/_build' 
    no previously-included directories found matching 'contrib' 
    no previously-included directories found matching 'tasks' 
    no previously-included directories found matching 'tests' 
Installing collected packages: pip 
    Found existing installation: pip 1.4.1 
    Uninstalling pip: 
Cleaning up... 
Exception: 
Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/basecommand.py", line 134, in main 
    status = self.run(options, args) 
    File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/commands/install.py", line 241, in run 
    requirement_set.install(install_options, global_options, root=options.root_path) 
    File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/req.py", line 1294, in install 
    requirement.uninstall(auto_confirm=True) 
    File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/req.py", line 525, in uninstall 
    paths_to_remove.remove(auto_confirm) 
    File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/req.py", line 1639, in remove 
    renames(path, new_path) 
    File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/util.py", line 294, in renames 
    shutil.move(old, new) 
    File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 300, in move 
    rmtree(src) 
    File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 247, in rmtree 
    rmtree(fullname, ignore_errors, onerror) 
    File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 252, in rmtree 
    onerror(os.remove, fullname, sys.exc_info()) 
    File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 250, in rmtree 
    os.remove(fullname) 
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/EGG-INFO/dependency_links.txt' 

Storing complete log in /Users/[me]/.pip/pip.log 

然而,PIP正確安裝到/usr/local/lib/python2.7/site-packages(家釀提供的版本),我也沒有明顯的問題,使用PIP模塊安裝和使用的模塊。以上全部爲which的輸出:

$ which pip 
/usr/local/bin/pip 
$ which python 
/usr/local/bin/python 

發生了什麼事?任何幫助,將不勝感激。

+0

這確實看起來很奇怪。我會嘗試:'/ usr/local/bin/python -E -m pip install --upgrade pip' – cel 2015-02-11 07:07:53

+0

'pip 1.4.1 from /Library/Python/2.7/site-packages/pip-1.4.1-py2。 7.egg'是OSX系統範圍的Python安裝,現在是Homebrew,你不應該搞砸它。確保從'/ usr/local/bin'運行'pip'二進制文件。 – 2015-02-11 08:07:09

+0

@MikkoOhtamaa我非常肯定當我運行'pip'時,''usr/local/bin/pip'正在執行,從'哪個pip'的輸出來判斷。我認爲這是合理的結論嗎? – dowbuen 2015-02-11 10:04:38

回答

7

我認爲這是這裏所描述的同樣的問題:https://github.com/pypa/pip/issues/2319

它是由點子行爲不端時,有在sys.path的另一PIP的雞蛋引起的。

最簡單的修復方法是繼續運行sudo python -m pip uninstall pip,直到停止工作,然後brew postinstall python(即重新安裝pip)。

+0

這對我有用,謝謝!該鏈接也有助於理解發生的事情。 – dowbuen 2015-02-20 18:54:56

+0

我知道這是一個兩年前的評論 - 但這真的幫了我很大的忙!謝謝 – gonzofish 2017-10-28 15:14:21

0

我也有這個問題(在優勝美地上的Homebrew Python 2.7.9)。我跑成試圖做pip install virtualenv

> which pip2.7 
/usr/local/bin/pip2.7 
> which python 
/usr/local/bin/python 
> pip install virtualenv 
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /Library/Python/2.7/site-packages 
> pip install --upgrade virtualenv 
.. 
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/virtualenv-1.11.5-py2.7.egg-info/dependency_links.txt' 

我通過隱藏文件/Library/Python/2.7/site-packages暫時解決了這個問題。當我完成時把它們移回去。

> pip install virtualenv 
Collecting virtualenv 
    Using cached virtualenv-12.0.7-py2.py3-none-any.whl 
Installing collected packages: virtualenv 

Successfully installed virtualenv-12.0.7 
> which virtualenv 
/usr/local/bin/virtualenv 
> 

它也能正常工作。我在virtualenv裏面得到了2.7.9,並且可以安裝numpymatplotlib,scipy,他們工作。