ubuntu-修改python默认版本

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012679583/article/details/82462070

在linux跑python脚本时默认是2.7版本,但是有许多组件在2.x已经摒弃了,最熟悉使用的还是3.x版本,为了一致性,不免要将linux系统上的python版本调整。
本机在ubuntu14.04 系统上进行更改设置。


1.查看本地已安装的python

root@ccrfox111:/home/wychen/python_code# ls /usr/bin/python*
/usr/bin/python-config   /usr/bin/python2.7-config  /usr/bin/python3.5          /usr/bin/python3m
/usr/bin/python2         /usr/bin/python3           /usr/bin/python3.5-config   /usr/bin/python3m-config
/usr/bin/python2-config  /usr/bin/python3-config    /usr/bin/python3.5m
/usr/bin/python2.7       /usr/bin/python3-petname   /usr/bin/python3.5m-config

可以看出我这里已经安装了2.7 和 3.5版本

2.查看可选的python版本列表

update-alternatives --list python

如果显示错误,则需要进行python可选版本的设置。

root@ccrfox111:/home/wychen/python_code# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
root@ccrfox111:/home/wychen/python_code# update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python (python) in auto mode

参数说明:

update-alternatives --install  <link> <name> <path> <priority>

python连接 名称 路径 优先级(数值越大表示优先级越高,这里3.5版本比2.7版本高)

3.再需要更改默认版本的时候可以执行以下命令

root@ccrfox111:/home/wychen/python_code# update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.5   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.5   2         manual mode

Press <enter> to keep the current choice[*], or type selection number:

输入0 1 2选择想设置的版本号就行了。

猜你喜欢

转载自blog.csdn.net/u012679583/article/details/82462070