【Python】杂 - macOS 下设置 Python 默认版本

Posted by 西维蜀黍 on 2019-10-06, Last Modified on 2025-04-23

步骤

1 修改可执行文件路径

打开配置文件,指定 python 命令对应的可执行文件路径:

$ open ~/.bash_profile

增加以下:

export PATH=/usr/local/Cellar/python/3.7.4_1/bin:${PATH}

注意,如果是使用 oh-my-zsh,则需要修改添加以上内容到~/.zshrc 中。

2 配置文件生效

$ source ~/.bash_profile

3 验证

使用 python 命令查看:

$ python
Python 2.7.15 (default, Aug 22 2018, 16:36:18)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Reference