gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:49:47 27 4
gpt4 key购买 nike

我在我的 Mac 上使用 Homebrew 安装了 Python 2.7.9,Homebrew 也安装了 pip。我的 Mac 上默认安装了一个未使用的旧版本 Python。

问题是,当我尝试升级 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(Homebrew 提供的版本),使用 pip 安装模块没有明显问题并使用模块。这是 which 的输出,在完成上述所有操作之后:

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

这是怎么回事?任何帮助将不胜感激。

最佳答案

我认为这与此处描述的问题相同:https://github.com/pypa/pip/issues/2319

这是由于在 sys.path 中有另一个 pip egg 时 pip 行为不正常造成的。

最简单的解决方法是继续运行 sudo python -m pip uninstall pip 直到停止运行,然后运行 ​​brew postinstall python(重新安装 pip)。

关于python - 在 Homebrew Python 2.7 安装中升级 pip 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28447915/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com