步骤
1 修改可执行文件路径
打开配置文件,指定 python 命令对应的可执行文件路径:
1 | $ open ~/.bash_profile |
增加以下:
1 | export PATH=${PATH}:/usr/local/Cellar/python/3.7.4_1/bin |
注意,如果是使用 oh-my-zsh,则也需要修改添加以上内容到 ~/.zshrc中。
2 配置文件生效
1 | $ source ~/.bash_profile |
Note
~/.bashrc
,~/.bash_profile
的区别:
- ~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息。仅在用户登录(直接使用物理机器登录,或者通过 ssh 进行登录)时,该文件会被执行一次。
- ~/.bashrc:该文件包含专用于你的bash shell的bash信息。当进行用户登录或者每次打开新的shell时,该文件都会被执行
3 验证
使用python命令查看:
1 | $ python |
Reference
- What is the difference between .bash_profile and .bashrc? - https://medium.com/@kingnand.90/what-is-the-difference-between-bash-profile-and-bashrc-d4c902ac7308