想彻底删除python3,但是感觉网上又没什么具体的好方法,就自己总结一下吧
对于安装的packages的话,例如tensorflow, 你可以使用
pip show tensorflow
它会显示这个包的信息,包括安装地址。
A framework /Library/Frameworks/Python.framework
, which includes the Python executable and libraries. The installer adds this location to your shell path. To uninstall MacPython, you can simply remove these three things. A symlink to the Python executable is placed in /usr/local/bin/.
简单来说就是
删除
/Library/Frameworks/Python.framework
删除
/usr/local/bin/
下的 python 链接(symlink)
官网pkg安装的python版本
第一步:删除框架
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
- 1
第二步:删除应用目录
sudo rm -rf "/Applications/Python 2.7"
- 1
第三步:删除指向python的链接
cd /usr/local/bin/
ls -l /usr/local/bin | grep '/Library/Frameworks/Python.framework/Versions/2.7' # 查看链接
brew prune # 清除链接和目录
- 1
- 2
- 3
- 4
- 5
清除后可再次查看链接,会发现链接已清除
附图:
homebrew安装的python版本
命令卸载:
brew uninstall python
- 1
最后,推荐使用homebrew安装python:
1. 可以指定python版本
2. 安装卸载都方便,避免对系统自带的python版本误操作
3. 安装某些软件时会连带安装python包,如果系统中已安装该版本包,但不是用brew安装的,就会引起冲突,导致安装失败
Homebrew only supports building against the System-provided Python or a
brewed Python. In particular, Pythons installed to /Library can interfere
with other software installs.
- 1
- 2
- 3
homebrew只支持编译系统默认和brew安装的python版本
来源 | python安装路径 |
---|---|
系统默认 | /System/Library/Frameworks/Python.framework/Versions/2.7 |
brew安装 | /usr/local/Cellar |
官网pkg安装 | /Library/Frameworks/Python.framework/Versions/2.7 |
推荐使用 Homebrew 来安装第三方工具。自己安装的python散落在电脑各处,删除起来比较麻烦。今天在此记录一下删除的过程(本人以Python3.6为例)。
删除Python 3.6 framework
sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.6
删除Python 3.6 应用目录
sudo rm -rf “/Applications/Python 3.6”
删除/usr/local/bin 目录下指向的Python3.6的连接
cd /usr/local/bin/
ls -l /usr/local/bin | grep ‘../Library/Frameworks/Python.framework/Versions/3.6’ | awk ‘{print $9}’ | tr -d @ | xargs rm
如果需要的话,编辑配置路径的环境文件,例如 ~/.bash_login, ~/.bash_profile, ~/.cshrc, ~/.profile, ~/.tcshrc, and/or ~/.zprofile,当初安装的时候,默认是将Python3.6的信息配置在 ~/.bash_profile 文件中,将其相关信息删除
欢迎关注微信公众号