相关文章推荐
高大的白开水  ·  Unable to update n8n ...·  4 月前    · 
含蓄的火腿肠  ·  How to Implement Row ...·  3 月前    · 
开心的炒粉  ·  GetKeyDown detection ...·  3 月前    · 
活泼的打火机  ·  Bug or (un)expected ...·  3 月前    · 
仗义的山羊  ·  if and switch ...·  3 年前    · 
坏坏的饭盒  ·  python - Getting ...·  3 年前    · 
俊逸的卡布奇诺  ·  Java ...·  3 年前    · 

Linux下修改默认Python版本

用户级

查看已安装的Python:

ls /usr/bin/python*

在 ~/.bashrc 中添加:

alias python= '/usr/bin/python3.6'

重新登陆生效。

系统级

查看可用Python版本:

update-alternatives --list python
update-alternatives: error: no alternatives for python

如果出现以上所示的错误信息,则表示 Python 的替代版本尚未被 update-alternatives 命令识别。想解决这个问题,我们需要更新一下替代列表,将 python2.7 和 python3.4 放入其中。

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2

--install 选项使用了多个参数用于创建符号链接。最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。这个例子中,我们为 /usr/bin/python3.4 设置的优先级为2,所以update-alternatives 命令会自动将它设置为默认 Python 版本。

切换替代版本:

update-alternatives --config python

移除替代版本:

update-alternatives --remove python /usr/bin/python2.7
发布于 2020-09-25 21:51

文章被以下专栏收录