1. 检查系统自带Python版本
python --version
2. 安装Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
安装完提示如下
Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the 'Next steps' section below.
==> Installation successful!
复制粘贴“Next Step”提示的命令行,添加路径
==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/leahchen/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
安装完成后,检查brew版本
brew -v
结果
Homebrew 4.1.17
安装brew过程中,命令行提示
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
如果想关闭,发送如下命令
export HOMEBREW_NO_ANALYTICS=1
3. 使用Homebrew安装Python
brew install python
安装完成,检查python 版本
python3 --version
结果
Python 3.9.6
4. 配置虚拟环境(配置虚拟环境名:myenv;激活环境)
python3 -m venv myenv
source myenv/bin/activate
结果:回车后在系统名称前有虚拟环境名称(myenv)
(myenv) sysname ~ %