在 macOS 上修改 Python 路径通常涉及以下步骤:
查看当前 Python 版本
在终端中输入 `python --version` 或 `python3 --version` 查看当前系统默认的 Python 版本。
配置 Python 路径
如果您使用的是 `.bash_profile` 文件,请打开终端并输入 `nano ~/.bash_profile`。
如果您使用的是 `.zshrc` 文件,请打开终端并输入 `nano ~/.zshrc`。
添加 Python 路径
在打开的文件中添加以下行,将 `/path/to/python` 替换为您系统中 Python 的安装路径:
export PATH="/path/to/python:$PATH"
保存修改
按下 `Control + X`,然后输入 `Y` 确认保存,再按下 `Enter` 退出编辑。
生效配置
在终端中输入 `source ~/.bash_profile` 或 `source ~/.zshrc` 使修改后的配置文件生效。
验证配置是否生效
在终端中输入 `which python3` 查看当前 Python 路径是否已经配置成功。
请注意,如果您使用的是 macOS Catalina 或更新版本,系统默认使用 Zsh 作为默认 shell,因此您可能需要编辑 `.zshrc` 文件。