ubuntu切换不同版本的python

有时候编译安卓或者SDK代码,如果报错,表示 Python 的替代版本尚未被update-alternatives 命令识别,此时需要切换到对应的版本才能正常编译。比如我在编译内核的时候出现了以下报错:

c 复制代码
  CC      security/selinux/netif.o
  CC      net/netfilter/core.o
  CC      lib/percpu_ida.o
  CC      net/llc/llc_input.o
  CC      drivers/base/driver.o
  CC      net/netfilter/nf_log.o
  CC      net/netfilter/nf_queue.o
Traceback (most recent call last):^C
Traceback (most recent call last):
  File "./scripts/gcc-wrapper.py", line 107, in <module>
  File "./scripts/gcc-wrapper.py", line 107, in <module>
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
  File "./scripts/gcc-wrapper.py", line 107, in <module>
  File "./scripts/gcc-wrapper.py", line 107, in <module>
Traceback (most recent call last):
Traceback (most recent call last):
  File "./scripts/gcc-wrapper.py", line 107, in <module>
Traceback (most recent call last):
    status = run_gcc()
  File "./scripts/gcc-wrapper.py", line 107, in <module>
  File "./scripts/gcc-wrapper.py", line 107, in <module>
  File "./scripts/gcc-wrapper.py", line 91, in run_gcc
Traceback (most recent call last):
Traceback (most recent call last):
  File "./scripts/gcc-wrapper.py", line 107, in <module>
    status = run_gcc()
    status = run_gcc()
  File "./scripts/gcc-wrapper.py", line 91, in run_gcc
Traceback (most recent call last):
      File "./scripts/gcc-wrapper.py", line 91, in run_gcc
status = run_gcc()
      File "./scripts/gcc-wrapper.py", line 107, in <module>
status = run_gcc()
  File "./scripts/gcc-wrapper.py", line 91, in run_gcc
      File "./scripts/gcc-wrapper.py", line 91, in run_gcc
status = run_gcc()

目前常用的python版本是3.8和2.7版本,可以通过 python --version 命令查看你当前的系统使用是哪个版本。

c 复制代码
caizd@drivers:~$ python --version
Python 2.7.17

sudo update-alternatives --list python 查看当前安装的所有Python版本:

c 复制代码
caizd@drivers:~/rk3399_linux/rk3399_linux$ sudo update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.8

如果出现报错表示 Python 的替代版本尚未被update-alternatives 命令识别到,此时需要执行命令安装一下。输入注意后面的1、2序号

c 复制代码
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1  
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2 

如果要切换python版本,使用 update-alternatives --config python命令,然后输入对应的数字,选择版本即可。

c 复制代码
caizd@drivers:~$ update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

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

Press <enter> to keep the current choice[*], or type selection number: 1
相关推荐
郝学胜-神的一滴9 分钟前
机器学习数据工程之基石:论数据集划分之道与sklearn实践
开发语言·人工智能·python·程序人生·机器学习·sklearn
轻竹办公PPT9 分钟前
AI生成PPT好用吗?工作总结场景下的工具排名更新
人工智能·python·powerpoint
SCBAiotAigc11 分钟前
bash前面的(base)实现的原理
人工智能·python·ubuntu
wa的一声哭了12 分钟前
内积空间 内积空间二
java·开发语言·python·spring·java-ee·django·maven
用户61354114601612 分钟前
nbsetup2.8.4128管理工具安装教程及工具详解
windows
小蒜学长21 分钟前
python餐厅点餐系统(代码+数据库+LW)
数据库·spring boot·后端·python
山土成旧客21 分钟前
【Python学习打卡-Day34】GPU为何“变慢”?从性能悖论到`__call__`的魔力
开发语言·python·学习
水龙吟啸25 分钟前
项目设计与开发:智慧校园食堂系统
python·机器学习·前端框架·c#·团队开发·visual studio·数据库系统
极客小云29 分钟前
【IEEE Transactions系列期刊全览:计算机领域核心期刊深度解析】
android·论文阅读·python
じ☆冷颜〃39 分钟前
基于多数据结构融合的密码学性能增强框架
数据结构·经验分享·笔记·python·密码学