mac自带的python版本是2.7,但市面上常用的python是python3,两者存在很大的差异,所以需要将mac中的python更新到3的版本
由于是刚学习python,对一些问题不是很懂所以在这里记录一下
在这里采用的是mac自带的brew工具来进行安装,本以为会非常简单的一个安装,却没想到遇坑不断
首先通过指令进行安装
brew search python
brew install python@3.9
然后出现了如下错误
==> Installing python@3.9 dependency: ca-certificates
==> Pouring ca-certificates-2022-04-26.all.bottle.tar.gz
Error: No such file or directory @ rb_sysopen - /Users/jiawei/Library/Caches/Homebrew/downloads/66ab11fb867e9c78860f502908686ed6f07cb9ecdae61bdeab62941e7c8a499c--ca-certificates-2022-04-26.all.bottle.tar.gz
网上一番查找发现需要先进行安装ca-certificates,通过
brew install ca-certificates
之后在安装python3.9时又会报如下错误
Installing dependencies for python@3.9: sqlite
==> Installing python@3.9 dependency: sqlite
==> Pouring sqlite-3.39.0.arm64_monterey.bottle.tar.gz
Error: No such file or directory @ rb_sysopen - /Users/jiawei/Library/Caches/Homebrew/downloads/6a28bef262faf8723bd4b879fc4c54a66094531a80d911b96c0c91471c09e93f--sqlite-3.39.0.arm64_monterey.bottle.tar.gz
然后又安装一番sqlite
这次在安装python3就可以了
最后配置一下python环境变量
open ~/.bash_profile
# 在配置文件上加上这两个,路径写成自己安装python的路径
alias python="/opt/homebrew/bin/python3"
PYTHON_PATH="/opt/homebrew/bin/python3"
最后通过 source ~/.bash_profile 进行一下配置就可以了