MacBook 自带的Python版本是Python2.7,可这个版本早就被淘汰了。我想彻底删除它
~ python
Python 2.7.15 (default, Nov 27 2018, 21:24:58)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
在终端输入python,显示版本是Python 2.7.15
再看python命令在什么位置
~ where python
/usr/local/bin/python
注意该路径其实是一个软链接(类似于Windows系统的快捷方式),通过ls
命令查看真实路径是在哪
~ ls -l /usr/local/bin/python
/usr/local/bin/python -> ../Cellar/python@2/2.7.15_1/bin/python
查到python2.7的真实路径是
/usr/local/Cellar/python@2/2.7.15_1/bin/python
不只是python这一个命令有设置了软连接,其实还有好多命令
ls -l /usr/local/bin | grep ../Cellar/python@2/2.7.15_1/bin/python
lrwxr-xr-x 1 wuchangfang admin 38 May 27 2021 python -> ../Cellar/python@2/2.7.15_1/bin/python
lrwxr-xr-x 1 wuchangfang admin 45 Dec 8 2018 python-config -> ../Cellar/python@2/2.7.15_1/bin/python-config
lrwxr-xr-x 1 wuchangfang admin 39 Dec 8 2018 python2 -> ../Cellar/python@2/2.7.15_1/bin/python2
lrwxr-xr-x 1 wuchangfang admin 46 Dec 8 2018 python2-config -> ../Cellar/python@2/2.7.15_1/bin/python2-config
lrwxr-xr-x 1 wuchangfang admin 41 Dec 8 2018 python2.7 -> ../Cellar/python@2/2.7.15_1/bin/python2.7
lrwxr-xr-x 1 wuchangfang admin 48 Dec 8 2018 python2.7-config -> ../Cellar/python@2/2.7.15_1/bin/python2.7-config
lrwxr-xr-x 1 wuchangfang admin 39 Dec 8 2018 pythonw -> ../Cellar/python@2/2.7.15_1/bin/pythonw
lrwxr-xr-x 1 wuchangfang admin 40 Dec 8 2018 pythonw2 -> ../Cellar/python@2/2.7.15_1/bin/pythonw2
lrwxr-xr-x 1 wuchangfang admin 42 Dec 8 2018 pythonw2.7 -> ../Cellar/python@2/2.7.15_1/bin/pythonw2.7
通通把软连接全部删掉
ls -l /usr/local/bin | grep '../Cellar/python@2/2.7.15_1' | awk '{print $9}' | tr -d @ | xargs rm
把python2.7整个目录也删掉
rm -rf /usr/local/Cellar/python@2/2.7.15_1
安装最新的python3.11
打开官网 https://python.org , 鼠标移动到 Downloads, 直接点击 Python3.11.3 下载 安装。
按照提示安装成功后在终端命令行输入python3.11确认是否安装成功
➜ python3.11
Python 3.11.3 (v3.11.3:f3909b8bc8, Apr 4 2023, 20:12:10) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
如果只想输入python命令就可以进入python解释器,你可以设置一个软链接
先查找python3.11的位置
➜ where python3.11
/usr/local/bin/python3.11
设置软连接
ln -s -f /usr/local/bin/python3.11 /usr/local/bin/python
测试
python --version
Python 3.11.3
本文完
关注公众号「Python之禅」,回复「1024」免费获取Python资源