It's possible to use pyenv to install and switch between multiple Python versions, which is helpful when trying to develop and test software targeted against versions of Python that aren't just the latest. One of the dependencies of these Python installations is readline, which is installed by brew.
The problem I have found is that brew periodically takes it upon itself to install a new version of readline. Although multiple versions of readline may be present on the system, only one of them is symlinked at /usr/local/opt/readline.
If brew upgrades to a new version of readline, suddenly Python starts spitting out text like ^[[A
when attempting to use cursor keys to line-edit. If you then attempt to explicitly import readline
you'll see an error like this:
>>> import readline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/********/.pyenv/versions/3.7.0/lib/python3.7/lib-dynload/readline.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
Referenced from: /Users/********/.pyenv/versions/3.7.0/lib/python3.7/lib-dynload/readline.cpython-37m-darwin.so
Reason: image not found
It is looking for /usr/local/opt/readline/lib/libreadline.7.dylib
. The problem appears to be that when pyenv install
built Python, /usr/local/opt/readline
was a symlink to /usr/local/Cellar/readline/7.0.5
which contained lib/libreadline.7.dylib
. That file is still present! But it's no longer available at this path, since brew has updated the symlink to point to version 8.
I can do brew switch readline 7.0.5
to swap these around again, and pyenv's Python will work again. But now Homebrew's Python is broken in much the same way. Is there any sensible way to have these co-exist and not spontaneously break again the next time Homebrew installs a new version of readline?
pyenv
can't trigger an update (rebuild) of its Python versions, even bumping thepyenv
package won't help. I've had such things happen to me all the time with other formulae. Related: github.com/Homebrew/homebrew-core/issues/37304 — you might consider filing a bug with Homebrew if you're using theirreadline
andpyenv
.