正常情况下mac终端输入python会显示Python 2.7
zhangxue@192 ~ % python
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Feb 29 2020, 01:55:37)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
若想在mac终端输入python后默认打开python3
- 在终端输入
which python3
- 在终端输入
vim ~/.bash_profile
- 按 i 或 a 进入编辑模式,然后输入
alias python="/Library/Frameworks/Python.framework/Versions/3.8/bin/python3"
- esc退回正常模式,然后输入 :wq 进入命令模式
- 在终端输入
source .bash_profile
- 在终端编辑 zsh 的配置文件/.zshrc
vi ~/.zshrc
- 按照上述方式在zshrc文件中加入
source .bash_profile
- 返回终端输入python
zhangxue@192 ~ % python
Python 3.8.3 (v3.8.3:6f8c8320e9, May 13 2020, 16:29:34)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.