升级Homebrew后pip3消失了

5

我使用 brew upgrade 命令升级了我的过时软件包,但是现在我发现之前存在的 pip3 命令(用于 Python 3 的 pip)不见了。我的 Python 3.6 安装还在:

cls@clsmba > python3
Python 3.6.5 (default, Mar 30 2018, 06:42:10) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

>pip 指向 Python 2.7 的 pip:

cls@clsmba ~> pip --version
pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)

cls@clsmba ~> pip2 --version
pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)

pip3.5 似乎是老版本 Python 3 的残留物:

cls@clsmba ~> pip3.5
Failed to execute process '/usr/local/bin/pip3.5'. Reason:
The file '/usr/local/bin/pip3.5' specified the interpreter '/usr/local/opt/python3/bin/python3.5', which is not an executable command.

我尝试使用get-pip.py来获取命令,但没有成功。
cls@clsmba ~> python3 get-pip.py
Requirement already up-to-date: pip in /usr/local/lib/python3.6/site-packages

现在我该怎么做才能干净地恢复命令?

使用brew reinstall python重新安装并没有安装pip。此外,请注意错误信息:

cls@clsmba > brew reinstall python
==> Reinstalling python 
==> Installing dependencies for python: sqlite
==> Installing python dependency: sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.23.1.sierra.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/75/75bf05c73a9b51101ea166742eb9baf285eda857fd98ea1d50a3abf0d81bd978?__gda__=exp=1523530592~hmac=ae4fc4056ff461c4fc3ca75983cd0f22c231e084312090e6c484aa59b02d3c1f&response-content-disposition=attachment%3Bfilename%3D%22sqlite-3.23.1.sierra.bottle.tar.gz%22&response-content-type=application%2Fgzip&requestInfo=U2FsdGVkX1-3IGgcJJtJX59zX8HP5dbhO9NFlYr07n9KOgP7AOcaoTM4pAOrLWqfH9MzbvCoUoNWKvWGRelKsrku6Kulv8WBBKAT7jGnTKBaYlEQpp1oEnHgh5nU-WVdBxk
######################################################################## 100.0%
==> Pouring sqlite-3.23.1.sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/sqlite/lib
    CPPFLAGS: -I/usr/local/opt/sqlite/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/sqlite/lib/pkgconfig

==> Summary
  /usr/local/Cellar/sqlite/3.23.1: 11 files, 3MB
==> Installing python
==> Downloading https://homebrew.bintray.com/bottles/python-3.6.5.sierra.bottle.tar.gz
Already downloaded: /Users/cls/Library/Caches/Homebrew/python-3.6.5.sierra.bottle.tar.gz
==> Pouring python-3.6.5.sierra.bottle.tar.gz
==> /usr/local/Cellar/python/3.6.5/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python/3.6.5/bin --install-lib=/usr/local/lib/python3.6/site-packages --single-version-externally-managed --record=installed.txt
Last 15 lines from /Users/cls/Library/Logs/Homebrew/python/post_install.01.python3:
copying setuptools/script (dev).tmpl -> build/lib/setuptools
copying setuptools/script.tmpl -> build/lib/setuptools
copying setuptools/cli-32.exe -> build/lib/setuptools
copying setuptools/cli-64.exe -> build/lib/setuptools
copying setuptools/cli.exe -> build/lib/setuptools
copying setuptools/gui-32.exe -> build/lib/setuptools
copying setuptools/gui-64.exe -> build/lib/setuptools
copying setuptools/gui.exe -> build/lib/setuptools
copying setuptools/command/launcher manifest.xml -> build/lib/setuptools/command
running install_lib
copying build/lib/easy_install.py -> /usr/local/lib/python3.6/site-packages
copying build/lib/pkg_resources/__init__.py -> /usr/local/lib/python3.6/site-packages/pkg_resources
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
  warnings.warn(msg)
error: could not delete '/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py': Permission denied
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall python`
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

If you need Homebrew's Python 2.7 run
  brew install python@2

Pip, setuptools, and wheel have been installed. To update them run
  pip3 install --upgrade pip setuptools wheel

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.6/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Summary

根据Mark Setchell的回答,将路径前缀添加到PATH中似乎并没有改变任何内容:
  bash-3.2$ echo $PATH
    /usr/local/opt/python/bin:/usr/local/sbin:/usr/local/Cellar/ruby/1.9.3-p194/bin:/usr/local/share/python3:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Library/TeX/texbin
    bash-3.2$ python
    Python 2.7.10 (default, Feb  7 2017, 00:08:15) 
    [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> ^D
    bas

h-3.2$ python3
Python 3.6.5 (default, Mar 30 2018, 06:42:10) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
bash-3.2$ pip3
bash: pip3: command not found
bash-3.2$ pip --version
pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)

没有错误,但仍然没有pip3命令。 - clstaudt
尝试运行 type pip3type python 等命令,查看它们指向哪里以及是否设置了任何可能会混淆事情的别名 - 请注意,which pip3 不如 type pip3 等命令有用。 - Mark Setchell
这是正确的,但我不确定是否可以安全地删除2s。我不知道有任何别名。我认为主要问题在于/usr/local/opt/python/bin中没有pip。 - clstaudt
1
视情况而定,但我倾向于备份,删除homebrew Python、Python3、Python2、Python@2、Python@3等。然后运行brew doctor直到您得到干净的健康状况报告,然后只需安装您想要的版本即可。 - Mark Setchell
@anothernode 是的,同意。我怀疑楼主的系统可能不太干净...找出问题可能比从头开始更难...如果你有其他建议,请随意提出...我也很乐意学习。 - Mark Setchell
显示剩余3条评论
2个回答

2
你需要决定它的工作方式,homebrew 可以为你提供方便。如果你运行以下命令,就可以获得相关信息:

brew info python

Python已安装为/usr/local/bin/python3。
已安装指向python3、python3-config、pip3等的未版本化符号链接python、python-config、pip等,分别指向/usr/local/opt/python/libexec/bin。
如果需要Homebrew的Python 2.7,请运行brew install python@2。
Pip、setuptools和wheel已安装。要更新它们,请运行pip3 install --upgrade pip setuptools wheel。
您可以使用pip3 install安装Python包。它们将安装到site-packages目录/usr/local/lib/python3.6/site-packages中。
因此:
- 如果您想使用版本化命令,即python3、pip3和idle3,请在PATH的开头放置/usr/local/opt/python/bin: export PATH=/usr/local/opt/python/bin:$PATH
- 如果您想使用未版本化命令表示Python3及其工具,即python、pip和idle,请在PATH的开头放置/usr/local/opt/python/libexec/bin: export PATH=/usr/local/opt/python/libexec/bin:$PATH
- 如果您想使用由苹果作为macOS的一部分提供的(古老的)Python v2.7,请在PATH的开头放置/usr/bin,并使用命令python: export PATH=/usr/bin:$PATH

很高兴知道它应该如何工作。然而,目前在我的系统上并非如此(请参见编辑)。 - clstaudt
这里没有pip:cls@clsmba > ls /usr/local/opt/python/bin 2to3 2to3-3.6 idle3 idle3.6 pydoc3 pydoc3.6 python3 python3-config python3.6 python3.6-config python3.6m python3.6m-config pyvenv pyvenv-3.6 - clstaudt

1
他们已经更改了Homebrew包中Python 3的默认命令为python3pip3,以符合PEP 394
如果pip3不起作用,建议重新安装Python:brew reinstall python
Homebrew 1.6.0起,brew install python会安装Python 3(和pip)。
您发布的关于 brew reinstall python 的输出错误显示,由于缺乏权限,无法删除 /usr/local/lib/python3.6/site-packages/pkg_resources/__init.py__

您是否检查了该文件的权限并验证了自己对其拥有写入权限?

如果没有,您可以使用以下命令添加写入权限:

chmod u+w /usr/local/lib/python3.6/site-packages/pkg_resources/__init.py

然后再尝试一次。


是的,看起来有些问题。在我的机器上,我没有收到...无法删除...错误,针对brew reinstall python。也许可以尝试brew uninstall --force python,然后再次安装? - anothernode
也许 brew doctor 可以提供一些关于安装出现问题的提示? - anothernode
我正在查看 brew doctor - 没有明显与问题相关的内容,但我会尝试逐一修复,以便homebrew不会混淆。 - clstaudt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接