gpt4 book ai didi

python - hombrew 升级后 pip3 消失了

转载 作者:太空宇宙 更新时间:2023-11-03 15:46:15 24 4
gpt4 key购买 nike

我用 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)

最佳答案

您需要决定您希望它如何工作,然后 homebrew 可以适应您。如果您运行以下信息,则信息可用:

brew info python

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 They will install into the site-package directory
/usr/local/lib/python3.6/site-packages


所以:

  • 如果你想使用versioned 命令,即python3pip3idle3,把/usr/local/opt/python/bin 在您的 PATH 开头:

    export PATH=/usr/local/opt/python/bin:$PATH

  • 如果您想使用未版本化命令来表示 Python3 及其工具,即 pythonpipidle,将 /usr/local/opt/python/libexec/bin 放在 PATH 的开头:

    export PATH=/usr/local/opt/python/libexec/bin:$PATH

  • 如果您想使用 Apple 提供的(古老的)Python v2.7 作为 macOS 的一部分,请将 /usr/bin 放在您的 PATH 的开头,然后使用命令 python :

    export PATH=/usr/bin:$PATH

关于python - hombrew 升级后 pip3 消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49793849/

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