我使用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:
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)
答案 0 :(得分:2)
您需要决定如何使用它,然后自制可以适应您。如果您运行,则可以获得这些信息:
brew info python
Python已安装为/ usr / local / bin / python3
无版符号符号链接
python
,python-config
,pip
等指向 分别是python3
,python3-config
,pip3
等 安装到/ 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-package目录中 /usr/local/lib/python3.6/site-packages
所以:
如果您想使用版本化命令,即python3
,pip3
和idle3
,请将/usr/local/opt/python/bin
放在你的路径:
export PATH=/usr/local/opt/python/bin:$PATH
如果您想使用非版本化命令来表示Python3及其工具,即python
,pip
和idle
,请{ {1}}在你的路径开头:
/usr/local/opt/python/libexec/bin
如果您想使用Apple提供的(古老)Python v2.7作为macOS的一部分,请将export PATH=/usr/local/opt/python/libexec/bin:$PATH
放在PATH的开头,并使用命令/usr/bin
:
python
答案 1 :(得分:1)
他们将Python 3的Homebrew包中的默认命令更改为python3
,pip3
符合PEP 394。
如果pip3
无法正常工作,请尝试重新安装Python:brew reinstall python
。
brew install python
安装了自Homebrew 1.6.0以来的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
然后再试一次。