1. 问题描述:
MacOs 删除自带 python 2.7 导致 git、xcode 等工具不能使用,错误日志如下:
error: unable to find utility “git”, not a developer tool or in PATH
2. 经过分析,原因如下:
更新了 python版本,目前的 python 版本不是 2.7;
删除了系统中自带的 python 2.7, 重新安装 python 官网提供的 python2.7 版本,但会缺少相关第三方的 lib,导致加载不了 Library;
小编的属于第 2 种情况
3.解决方案:
删除已经安装的 python 版本,导入系统自带的 python 2.7 包,其中包含一系列第三方 lib。
1)删除通过 brew 安装的 python:
brew uninstall python
2) 删除通过 pkg 安装的包
sudo rm -rf /Library/Frameworks/Python.framework/Versions/*
3)删除系统中的软连接
sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/*
sudo rm -f /usr/bin/python
4) 导入系统的 python 包:
下载地址:
链接:https://pan.baidu.com/s/1dSqhXG 密码:0tl9
解压下载得到的包到目录 2.7;
复制目录:
cp -r 2.7 /System/Library/Frameworks/Python.framework/Versions/
建立软连接:
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /usr/bin/python
试试,git、xcode 等工具应该可以正常使用了!