ubuntu-修改python默认版本

心已赠人 2022-05-14 10:22 344阅读 0赞

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


1.查看本地已安装的python

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

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

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

  1. update-alternatives --list python

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

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

参数说明:

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

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

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

  1. 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 ------------------------------------------------------------
  2. * 0 /usr/bin/python3.5 2 auto mode
  3. 1 /usr/bin/python2.7 1 manual mode
  4. 2 /usr/bin/python3.5 2 manual mode
  5. Press <enter> to keep the current choice[*], or type selection number:

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

发表评论

表情:
评论列表 (有 0 条评论,344人围观)

还没有评论,来说两句吧...

相关阅读

    相关 修改Ubuntu默认Shell

    奇怪的错误 在linux下的shell脚本中,第一行一般会指明该脚本的执行程序名,以便为该脚本拥有执行权限时可以通过脚本名直接运行。  我在控制台上一般通过 sh 命令