How to uninstall Python from Mac OS
There are two ways for installing Python on OS X/Mac, and they would affect how to uninstall python.
(1) “.pkg” from Python.org
(2) Installed through Homebrew
But sometimes we just got the wrong versions or we just want to remove the .pkg version of Python from your Mac ! Therefor, I wrote the solution down ! There will introduce two solutions of situation what I talked about !
Identify installation path
Check the python execution file exists in this path as below:
“/Library/Frameworks/Python.framework/Versions/3.5/bin/”
Note: You have to modify “Versions” to match the version of Python that you installed.
1 2 3 4 5 6 7 8 9 10 |
Andy-MBP:bin Andy$ cd /Library/Frameworks/Python.framework/Versions/3.5/bin/ Andy-MBP:bin Andy$ ls -l python* lrwxr-xr-x 1 root admin 9 2 8 12:40 python3 -> python3.5 lrwxr-xr-x 1 root admin 12 2 8 12:40 python3-32 -> python3.5-32 lrwxr-xr-x 1 root admin 16 2 8 12:40 python3-config -> python3.5-config -rwxrwxr-x 2 root admin 25920 1 17 2017 python3.5 -rwxrwxr-x 1 root admin 13568 1 17 2017 python3.5-32 lrwxr-xr-x 1 root admin 17 2 8 12:40 python3.5-config -> python3.5m-config -rwxrwxr-x 2 root admin 25920 1 17 2017 python3.5m -rwxrwxr-x 1 root admin 2081 1 17 2017 python3.5m-config |
Remove Python’s folders
Remove Python’s folders that installed by .pkg downloaded from Python.org.
If you are in the “Python.framework” right now, please change your directory before begin this step!
1 2 |
Andy-MBP:~ Andy$ cd ~ Andy-MBP:~ Andy$ sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.5/ |
This instruction means removing all versions of Python.
1 |
Andy-MBP:~ Andy$ sudo rm -rf /Library/Frameworks/Python.framework/ |
Remove “Applications” folder in OS X(Mac)
Now, we can remove the folders of Python from the “Applications”.
Note: Change the version of Python, if you need.
1 |
Andy-MBP:~ Andy$ sudo rm -rf /Applications/Python\ 3.5 |
Remove soft links
Remove these links are related to Python in “/usr/local/bin”.
Way 1: delete only one version
1 |
Andy-MBP:~ Andy$ sudo find /usr/local/bin -type l -and -lname "*/Library/Frameworks/Python.framework/Versions/3.5*" -delete |
Way 2: delete all versions
1 |
Andy-MBP:~ Andy$ sudo find /usr/local/bin -type l -and -lname "*/Library/Frameworks/Python.framework/*" -delete |
Restore settings in .bash_profile
This setting I will mention below may exist in two files: “~/.bash_profile” or “~/.profile”
1 |
Andy-MBP:~ Andy$ sudo vim ~/.bash_profile |
Let’s comment out this text in as below:
It contains the libraries path of Python!
1 |
# PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}" |
Remove Python
It’s the simplest way to manage your packages in OS X(Mac) !
First of all, lists what packages you install through Homebrew.
Instruction: “brew list”
1 2 3 4 |
Andy-MBP:~ Andy$ brew list autoconf gdbm libksba node phantomjs readline automake icu4c libtool openssl pkg-config sqlite coreutils libgpg-error libyaml openssl@1.1 python3 xz |
Execute remove instruction “brew uninstall <package name>“.
1 |
Andy-MBP:~ Andy$ brew uninstalll python3 |
Finished !
It’s so cool, isn’t it ?
Pingback:OS X 完整移除 Python - BrilliantCode.net