无法在 ubuntu 中将默认 python 版本设置为 python3 [英] Unable to set default python version to python3 in ubuntu

查看:27
本文介绍了无法在 ubuntu 中将默认 python 版本设置为 python3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Ubuntu 16.04 中将默认 Python 版本设置为 python3.默认情况下它是 python2 (2.7).我按照以下步骤操作:

I was trying to set default python version to python3 in Ubuntu 16.04. By default it is python2 (2.7). I followed below steps :

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3

但是我收到第二个语句的以下错误,

but I'm getting the following error for the second statement,

rejeesh@rejeesh-Vostro-1015:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs <link> <name> <path> <priority>

Use 'update-alternatives --help' for program usage information.   

我是 Ubuntu 的新手,我不知道我做错了什么.

I'm new to Ubuntu and Idon't know what I'm doing wrong.

推荐答案

我在年轻和天真时写的,update-alternatives 是更好的方法.请参阅@Pardhu 的回答.

I wrote this when I was young and naive, update-alternatives is the better way to do this. See @Pardhu's answer.

过时的答案:

打开您的 .bashrc 文件 nano ~/.bashrc.输入 alias python=python3到文件顶部的新行,然后使用 ctrl+o 保存文件并使用 ctrl+x 关闭文件.然后,回到你的命令行类型source ~/.bashrc.现在您的别名应该是永久的.

Open your .bashrc file nano ~/.bashrc. Type alias python=python3 on to a new line at the top of the file then save the file with ctrl+o and close the file with ctrl+x. Then, back at your command line type source ~/.bashrc. Now your alias should be permanent.

这篇关于无法在 ubuntu 中将默认 python 版本设置为 python3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆