Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

python - pip3 gone after hombrew upgrade

I upgraded my outdated packages with brew upgrade, but now I find that the pip3 command (pip for Python 3) that I previously had is gone. My Python 3.6 installation is still there:

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 points to pip for 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 seems to be a leftover from an older Python 3 version:

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.

I tried using get-pip.py to get the command back, but that didn't work:

cls@clsmba ~> python3 get-pip.py
Requirement already up-to-date: pip in /usr/local/lib/python3.6/site-packages

What can I do now to get the command back in a clean way?

Reinstalling with brew reinstall python did not install pip. Also, note the error message:

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

Prepending to the PATH acoording to @Mark Setchell's answer does not seem to change things:

  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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to decide how you want it to work and homebrew can then accommodate you. The information is available if you run:

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


So:

  • if you want to use versioned commands, i.e python3, pip3 and idle3, put /usr/local/opt/python/bin at the start of your PATH:

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

  • if you want to use un-versioned commands to mean Python3 and its tools, i.e.python, pip and idle, put /usr/local/opt/python/libexec/bin at the start of your PATH:

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

  • if you want to use the (ancient) Python v2.7 supplied by Apple as part of macOS, put /usr/bin at the start of your PATH, and use the command python:

    export PATH=/usr/bin:$PATH


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...