pip3 gone after hombrew upgrade

2019-01-26 18:58发布

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
                

2条回答
Summer. ? 凉城
2楼-- · 2019-01-26 19:26

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

查看更多
相关推荐>>
3楼-- · 2019-01-26 19:27

They changed the default commands in the Homebrew package for Python 3 to be python3 and pip3 to be compliant with PEP 394.

If pip3 doesn't work I'd try reinstalling Python: brew reinstall python.

brew install python installs Python 3 (and pip) since Homebrew 1.6.0.


The error in the output for brew reinstall python that you posted says that /usr/local/lib/python3.6/site-packages/pkg_resources/__init.py__ cannot be deleted because of lacking permissions.

Have you checked the permissions of that file and verified that you have write permissions on it?

If not, you can add write permissions with

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

and then try again.

查看更多
登录 后发表回答