在Linux中如何设置Python,以便在使用python时将使用python3而不是python 2.7

问题描述

当我键入python --version时,它给出了python --version,我希望使用python3认行为。我不需要每次创建运行python时都必须键入“ python3”。在Linux中,我会更改吗?

解决方法

在您的~/.bash_profile中,添加以下内容:

export PATH=/Users/reblochonmasque/anaconda3/envs/py38/bin/:$PATH
alias python3=/Users/reblochonmasque/anaconda3/envs/py38/bin/python
alias python=/Users/reblochonmasque/anaconda3/envs/py38/bin/python

export PATH=/Users/reblochonmasque/anaconda3/envs/py2k/bin/:$PATH
alias python2=/Users/reblochonmasque/anaconda3/envs/py2k/bin/python

PATH替换为系统上python安装的路径;就像这样

export PATH=/usr/local/bin:$PATH

通过别名,您可以在命令行中使用pythonpython3启动python3,并使用python2启动python2