mac安装 Python3

535 阅读1分钟

mac 电脑自带 python,但版本是 python2,输入 python 命令查看版本,可以看到版本是 2.7.16,或者输入 pythons3 --version

先安装Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

因为我之前按其他方式操作过,下载了些东西,所以这步有报错fatal: destination path '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core' already exists and is not an empty directory.

解决方法:删掉原来的目录

cd /usr/local
sudo rm -rf Library .git .gitignore bin/brew README.md share/man/man1/brewsudo rm -rf Homebrewrm -rf ~/Library/Caches/Homebrew

然后再执行

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

如果没报错,可忽略上面的操作,看你是否有在Cloning into这步卡住

如果卡出了 control+c 中断脚本,然后执行以下命令

cd "$(brew --repo)/Library/Taps/"
mkdir homebrew && cd homebrew
git clone git://mirrors.ustc.edu.cn/homebrew-core.git

执行后可以看到,下载速度快的飞起,立马就装好了

安装完成后,你可以用 brew doctor 检查一下是否安装成功

安装 Python

然后执行 brew install python3

完成后可用这个命令查看版本 python3 --version