简体   繁体   English

在Homebrew Python 2.7安装中升级pip的问题

[英]Problems with upgrading pip in Homebrew Python 2.7 installation

I've got Python 2.7.9 installed using Homebrew on my Mac, and Homebrew also installs pip. 我在Mac上使用Homebrew安装了Python 2.7.9,而Homebrew也安装了pip。 There's also an older, unused version of Python that was installed by default on my Mac. 还有一个较旧的,未使用过的Python版本,默认安装在我的Mac上。

The problem is that when I try to upgrade pip (using pip install --upgrade pip ), pip seems to want to upgrade the version of pip that comes with the older, default version of Python. 问题是,当我尝试升级pip时(使用pip install --upgrade pip ),pip似乎想要升级旧的默认版本的Python附带的pip版本。 Here's what happens (after doing a fresh install of Python 2.7.9, ie, brew remove python followed by brew install python ): 这是发生了什么(在完成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)

The above seems correct. 以上似乎是正确的。 However, the following happens: 但是,会发生以下情况:

$ 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

Why was pip 1.4.1 installed? 为什么安装了pip 1.4.1? Now I get: 现在我得到:

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

That seems to correspond to the older default version of Python. 这似乎与Python的旧版默认版本相对应。 When I try to upgrade again, it fails: 当我再次尝试升级时,它会失败:

$ 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

However, pip installs correctly to /usr/local/lib/python2.7/site-packages (the Homebrew-provided version), and I have no apparent issues with using pip to install modules and using the modules. 但是,pip正确安装到/usr/local/lib/python2.7/site-packages提供的版本),使用pip安装模块和使用模块没有明显的问题。 Here's the output of which , after all of the above: 下面是输出的which ,毕竟上面的:

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

What's going on? 这是怎么回事? Any help would be appreciated. 任何帮助,将不胜感激。

I think this is the same issue described here: https://github.com/pypa/pip/issues/2319 我认为这与此处描述的问题相同: https//github.com/pypa/pip/issues/2319

It's caused by pip misbehaving when there's another pip egg in sys.path. 当sys.path中有另一个pip egg时,它是由pip行为异常造成的。

The easiest fix is to keep running sudo python -m pip uninstall pip until that stops working, and then brew postinstall python (which reinstalls pip). 最简单的解决方法是继续运行sudo python -m pip uninstall pip直到停止工作,然后brew postinstall python (重新安装pip)。

I had this problem too (Homebrew Python 2.7.9 on Yosemite). 我也有这个问题(Yosemite上的Homebrew Python 2.7.9)。 I ran it into trying to do pip install virtualenv : 我把它运行到试图做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'

I solved it by hiding the files in /Library/Python/2.7/site-packages temporarily. 我通过暂时隐藏/Library/Python/2.7/site-packages的文件解决了这个问题。 And moving them back when I was finished. 当我完成时将它们移回去。

> 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
>

It works properly too. 它也可以正常工作。 I get 2.7.9 inside the virtualenv and can install numpy , matplotlib , scipy , and they work. 我在virtualenv中得到2.7.9并且可以安装numpymatplotlibscipy ,并且它们可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM