What to do if pip gives a DistributionError in Homebrew

phenomenon

When I run the pip command, I get an error like pkg_resources.DistributionNotFound: pip == 1.5.4 and can't do anything.

Reproduction procedure

  1. Install Python with Homebrew
  2. With a new pip, do pip install --upgrade pip

brew install python and then

==> Caveats
Setuptools and Pip have been installed. To update them
  pip install --upgrade setuptools
  pip install --upgrade pip

However, if I upgrade pip according to this, pip will not work. / usr / local / bin / pip is still out of date even though pip has been upgraded.

Coping

You can start pip with python -m pip. Delete / usr / local / bin / pip

$ rm /usr/local/bin/pip /usr/local/bin/pip2 /usr/local/bin/pip2.7
$ python -m pip install --upgrade --force-reinstall pip

Or

$ python -m pip install --upgrade --force-reinstall pip --no-use-wheel

To do. If you use the latter method, whenever you upgrade pip or setuptools in the future,

$ pip install --upgrade --no-use-wheel pip setuptools

need to do it.

Cause

This is a compatibility issue between Homebrew and wheel.

Homebrew uses pip and setuptools when installing Python

/usr/local/Cellar/python/<version>/

Install it under it, and install symlink to the pip command etc. in ``` / usr / local / bin / .

Then, write the setting prefix = / usr / local in distutils.cfg, and the package that is normally installed by pip install etc. is a script under/ usr / local / bin /, / usr Make sure the libraries are installed under /local/lib/pytthon2.7/.

When I do pip install --upgrade pip in this state, I want to install the / usr / local / bin / pip script, but there is already a symlink that Homebrew does not detect. ..

The behavior when the symlink is already in the place where you want to install the script, but it is different between the installation from wheel and the installation from tar.gz, in the case of wheel it can not be installed and it is skipped, in the case of tar.gz Will rewrite the symlink's link (that is, the contents of Cellar).

Modern pips use the wheel by default, which leaves symlinks for scripts that try to use older versions of pip under Cellar, making them unbootable.

I don't think it's good that the behavior is different when using wheel and when not using it, but since there is no correct answer when installing by overwriting symlink created externally, Homebrew is pip install- If you allow -upgrade pip, I think you should install pip normally from the beginning.

Postscript

I have issued a Pull request that fixes pip and setuptools to stop installing inside Cellar. https://github.com/Homebrew/homebrew/pull/29926

Addendum 2

The above PR was rejected because it did not match Homebrew's basic policy. So, just like when you don't use the wheel when installing with the wheel, you can publicize the fix to the pip side to overwrite (the link destination) even if the symbolic link already matches the script installation destination. It was captured.

Once the next pip (1.6.0) is released and bundled with Homebrew's Python, you should be able to upgrade normally with pip install --upgrade pip from the next version.

That said, there are two pips inside and outside the Celler, and the script inside is rewritten when installing outside, which is far from smart. Unless you're in trouble, we recommend that you don't upgrade pip and wait for Homebrew to update.

Also, heavy Python developers may prefer to build their own using MacPorts or pyenv rather than Homebrew, which is forced by its own method. pip install --upgrade pip has been fixed, but pip install --user ipython is still stuck and I don't know what other side effects there are around packaging.

Recommended Posts

What to do if pip gives a DistributionError in Homebrew
What to do if a UnicodeDecodeError occurs in pip
What to do if pip install fails in Xcode 5.1
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do if you get a minus zero in Python
What to do if you get a UnicodeDecodeError with pip install
What to do if pipreqs results in UnicodeDecodeError
Note: What to do if pip install fails
What to do if pip cannot be installed
What to do if there is a decimal in python json .dumps
What to do if you can't install with pip in babun environment
What to do when a warning message is displayed in pip list
What to do if pip --user returns an error in a virtual environment created with pyenv
What to do if you can't pip install mysqlclient
What to do if pip install fails to install dependent libraries
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
What to do if you get a "No versions found" error in pipenv
What to do if a Unicode Encode Error occurs in Sublime Text Python
What to do if NotADirectoryError: [Errno 20] Not a directory:'xdg-settings' appears in jupyter notebook
What to do if a version error occurs in the selenium Chrome driver
What to do if yum breaks
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
What to do if you get "coverage unknown" in Coveralls
What to do if `pip install matplotlib` fails on Mac
What to do if you can't log in as root
What to do if pip install mysqlclient fails on MacOS
What to do if you get a Cannot retrieve metalink for repository error in yum
What to do if you can't install pyaudio with pip #Python
What to do if "Unnamed: 0" is added in to_csv-> read_csv in pandas
What to do if you can't use the trash in Lubuntu 18.04.
What to do if you get angry with'vertices' must be a 2D list ... in matplotlib arrow
What to do if you get a must override `get_config` error when trying to model.save in Keras
[Memorandum] What to do when a warning appears after executing pip list
What to do if you can't find PDO in Laravel or CakePHP
What to do if you can't use scikit grid search in Python
What to do if you get lost in file reference with FileNotFoundError
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if No Python documentation found for ... appears in pydoc
What to do if you get a TypeError with numpy min, max
What to do if you get Could not fetch URL 443 with pip
What to do if fprintd requires a password when registering your fingerprint
What happens if you do "import A, B as C" in Python?
[OSX] [pyenv] What to do when an SSL error occurs in pip
What to do if you can't pipenv shell
What to do if mod_fcgid cannot resolve UnicodeEncodeError
What to do if rails s doesn't work
What to do if PyInstaller3.5 gives an error in Python3.8 (TypeError: an integer is required (got type bytes))
[Python] What to do if you get a ModuleNotFoundError when importing pandas using Jupyter Notebook in Anaconda
What to do if atom autocomplete-python doesn't work
What to do to get google spreadsheet in python
What to do if Docker-sync suddenly stops working
What to do if a symbolic link error occurs in import cv while trying to install OpenCV in Python
What to do if "amazon-linux-extras" → "No module named amazon_linux_extras"
What to do when SSL error occurs in pip in Windows10, miniconda, VScode environment
What to do when a warning appears around Python integration in Neovim's CheckHealth
What to do if scrapy doesn't work after installing scrapy with pip on mac
What to do if Django can't load an image from a static folder
What to do if you get "Python not configured." Using PyDev in Eclipse
What to do if abort is displayed when inputting camera video in OpenCV
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'