How to update macOS Python packages

4.1k views Asked by At

I've been getting the following notice every time I fire up Terminal recently:

/usr/local/lib/python3.5/site-packages/powerline/bindings/zsh/powerline.zsh:200: /usr/local/bin/powerline-config: bad interpreter: /usr/local/opt/python3/bin/python3.5: no such file or directory /usr/local/lib/python3.5/site-packages/powerline/bindings/zsh/powerline.zsh:204: /usr/local/bin/powerline-config: bad interpreter: /usr/local/opt/python3/bin/python3.5: no such file or directory'

I posted this to the powerline GitHub page as an issue and was advised that I have probably updated my Python version on macOS without me knowing (through homebrew or perhaps through a system update, since I'm a macOS Beta user).

Is there a way to update Python packages en-masse in macOS as in Gentoo, as pointed out in the linked GitHub issue? The dev mentioned that there is a python-updater script in Gentoo that is used to update packages after updating Python, but no such script exists for macOS.

OS: macOS 10.12.3 Beta

Any help would be appreciated!

-- paanvaannd

1

There are 1 answers

1
bnaecker On BEST ANSWER

I think the diagnosis from the powerline GitHub page is correct: you updated Python 3.5 to 3.6 via Homebrew, so things expecting the 3.5 interpreter are broken. I've done this a couple of times.

The best way I've found to keep things sane is to store a list of the installed packages, remove them, update Python via Homebrew, and then reinstall the list of packages. In the shell this would be:

$ pip3 list | cut -d " " -f 1 > package-list.txt # Store package names without versions
$ pip3 uninstall -y $(cat package-list.txt) # Cannot use redirection
$ brew update && brew upgrade python3
$ pip3 install $(cat package-list.txt)

This isn't very helpful for you now, because you've already upgraded with out keeping this list. One option is to roll back your Python installation via Homebrew. If you've not yet done brew cleanup, you can do brew switch python3 3.5.x (where x is the latest version you had). After this, you can do the procedure above, swapping brew upgrade python3 with brew switch python3 3.6.0.

If you've cleaned up the previous installation, you can try to reinstall it, using this answer, and then do the above.

If both those fail, you can just manually re-install your packages. Look at what's in /usr/local/lib/python3.5/site-packages/ for a list of the packages you had installed via Pip, and install them manually. The best thing is to pick one with lots of dependencies, so that you install many packages at once.