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
相关推荐
uoscn3 分钟前
Ubuntu24.04无操作卡死,无法唤醒问题以及内核版本切换记录
linux·ubuntu
yaoh.wang9 分钟前
力扣(LeetCode) 67: 二进制求和 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
大猫和小黄19 分钟前
Windows环境下使用Nacos搭建若依(RuoYi)微服务版完整指南
windows·微服务·架构
电饭叔21 分钟前
自定义重载运算符--《python语言程序设计》2018版--第8章20题使用Rational类求和数列之一
开发语言·python
网硕互联的小客服22 分钟前
CC攻击对服务器正常运行会有什么影响?如何预防和解决CC攻击?
运维·服务器·网络·windows·安全
Evan芙24 分钟前
基于Nginx和Python的动态站点安装配置
数据库·python·nginx
工具人555526 分钟前
python 环境问题
开发语言·python
小鸡吃米…28 分钟前
Python编程语言面试问题三
开发语言·python·面试
yaoh.wang31 分钟前
力扣(LeetCode) 58: 最后一个单词的长度 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
深蓝海拓34 分钟前
PySide6从0开始学习的笔记(七) 控件(Widget)之文字输入类控件
笔记·python·qt·学习·pyqt