DEV Community

darkmage
darkmage

Posted on

Clean up and remove a Python3 homebrew install

tl;dr TIL pygame is broken using homebrew Python3, so I decided to wipe my shit and start from scratch. I figured I'd give you the quickness on what I did so next time this shit happens to someone, they have a handy reference.

https://stackoverflow.com/questions/11248073/what-is-the-easiest-way-to-remove-all-packages-installed-by-pip

TIL about pip freeze:

freeze  Output installed packages in requirements format.
Enter fullscreen mode Exit fullscreen mode

Save the requirements to file if you want to quickly re-install everything you're about to remove.

pip3 freeze > requirements.txt
pip3 freeze | xargs pip3 uninstall -y

Enter fullscreen mode Exit fullscreen mode

https://apple.stackexchange.com/questions/284824/remove-and-reinstall-python-on-mac-can-i-trust-these-old-references

rm -rfv /usr/local/bin/python3*
Enter fullscreen mode Exit fullscreen mode

Ok, time to install official Python3.

At this point you can do pip3 install -r requirements.txt to reinstall everything you uninstalled. I'm keeping my stuff cleaner for now ^_^!


To reiterate:

pip3 freeze > requirements.txt
pip3 freeze | xargs pip3 uninstall -y
rm -rfv /usr/local/bin/python3*
# Reinstall python3 here!
pip3 install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

If you need a Computer Science tutor, code reviewer, or just someone to pair program with, hit me up

Top comments (1)

Collapse
 
janthonyfields profile image
Anthony Fields • Edited

Thanks! A note:
If you originally installed python3 via homebrew, you might also want to use

brew doctor

(and prior to homebrew version 1.9.0):

brew cleanup --prune

(or version 1.9.0+)

brew cleanup

(homebrew 1.90 deprecates prune in favor of just cleanup)

...as detailed in the above mentioned link:

I'm new to the mac, and apparently I've made some sort of error. I've been learning python, via tutorials, and between Homebrew, Pip and XCode somehow my versions are all mixed. Pip3 points to python2, so all my python3 trials fail, etc...

I'm researching how to safely remove all versions…