背景:新到了mac,开始安装环境
第一步:安装brew
Homebrew官网:
Homebrew — The Missing Package Manager for macOS (or Linux)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
使用命令行时报错:
curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 19 ms: Couldn't connect to server
【解决】到github上下载.pkg包安装,homebrew安装包地址:
Release 4.2.0 · Homebrew/brew · GitHub
Release 4.1.24 · Homebrew/brew · GitHub
安装 homebrew时的提示:
This package will install to:
⁃ /opt/homebrew on Apple Silicon
⁃ /usr/local/bin/brew and /usr/local/Homebrew on Intel
第二步:安装 命令行工具
Command Line Tools (CLT) are missing
You must install the Command Line Tools (CLT) before installing Homebrew by running xcode-select --install
from a Terminal.
按照提示执行xcode-select --install
已安装后提示:
xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
第三步:安装python
mac自带的python版本是:
testmanzhang@TestMandeMBP ~ % python3 --version
Python 3.9.6
升级python:
brew upgrade python
提示:
Error: The following directories are not writable by your user:
/usr/local/opt
You should change the ownership of these directories to your user.
sudo chown -R testmanzhang /usr/local/opt
And make sure that your user has write permission.
chmod u+w /usr/local/opt
【解决】下载python安装包安装
添加Python环境变量:
vi ~/.zshrc
PATH="/Library/Frameworks/Python.framework/Versions/3.12/bin:${PATH}"
export PATH
alias python="/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12"