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
相关推荐
烛阴2 小时前
武装你的Python“工具箱”:盘点10个你必须熟练掌握的核心方法
前端·python
杨枝甘露小码2 小时前
Python学习之基础篇
开发语言·python
我是华为OD~HR~栗栗呀3 小时前
23届考研-Java面经(华为OD)
java·c++·python·华为od·华为·面试
让子弹飞023 小时前
永久解决ubuntu网络连接问题
linux·运维·ubuntu
小蕾Java3 小时前
PyCharm 软件使用各种问题 ,解决教程
ide·python·pycharm
Lucky_Turtle3 小时前
【PyCharm】设置注释风格,快速注释
python
kunge1v53 小时前
学习爬虫第四天:多任务爬虫
爬虫·python·学习·beautifulsoup
萧鼎4 小时前
Python schedule 库全解析:从任务调度到自动化执行的完整指南
网络·python·自动化
B站_计算机毕业设计之家5 小时前
机器学习实战项目:Python+Flask 汽车销量分析可视化系统(requests爬车主之家+可视化 源码+文档)✅
人工智能·python·机器学习·数据分析·flask·汽车·可视化
羊羊小栈5 小时前
基于「多模态大模型 + BGE向量检索增强RAG」的航空维修智能问答系统(vue+flask+AI算法)
vue.js·人工智能·python·语言模型·flask·毕业设计