mac最新版本下自带python3,我想使用python2.7.18,我应该怎么做
时间: 2024-04-10 14:27:47 浏览: 407
你可以按照以下步骤在 macOS 最新版本中安装 Python 2.7.18:
1. 首先,确保你已经安装了 Homebrew(一个 macOS 的软件包管理器)。如果你还没有安装 Homebrew,请打开终端并执行以下命令:
```shell
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
2. 安装 Python 2.7.18。在终端中运行以下命令:
```shell
brew install python@2
```
3. 这将安装 Python 2.7.18,并将其可执行文件链接到 `/usr/local/bin/python2`。你可以通过运行以下命令检查 Python 安装的版本:
```shell
python2 --version
```
如果显示的是 `Python 2.7.18`,则说明安装成功。
4. 为了避免与 macOS 自带的 Python 3 冲突,你可以将 Python 2 的可执行文件链接到 `/usr/local/bin/python2`。在终端中运行以下命令:
```shell
echo 'export PATH="/usr/local/opt/python@2/libexec/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
```
这将确保在运行 `python` 命令时,默认使用的是 Python 2.7.18。
现在,你应该能够在 macOS 最新版本中使用 Python 2.7.18 了。请注意,Python 2 已于2020年停止维护,推荐尽快迁移到 Python 3。
阅读全文
相关推荐













