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
相关推荐
代码的乐趣7 分钟前
支持selenium的chrome driver更新到136.0.7103.94
chrome·python·selenium
小猪写代码16 分钟前
在 Ubuntu 20.04.6 LTS 中将 SCons 从 3.1.2 升级到 4.9.1
chrome·ubuntu·pip
渴望技术的猿30 分钟前
Windows 本地部署MinerU详细教程
java·windows·python·mineru
Aliano2171 小时前
TestNGException ClassCastException SAXParserFactoryImpl是Java自带的Xerces解析器——解决办法
java·开发语言·python
漫谈网络1 小时前
回调函数应用示例
开发语言·python·回调函数
南棱笑笑生1 小时前
20250517让NanoPi NEO core开发板在Ubuntu core16.04.2下支持TF卡的热插拔
linux·运维·ubuntu
亚林瓜子1 小时前
pyenv简单的Python版本管理器(macOS版)
开发语言·python·macos·pyenv
青钰未央2 小时前
14、Python时间表示:Unix时间戳、毫秒微秒精度与time模块实战
python·改行学it
byte轻骑兵2 小时前
摩方 12 代 N200 迷你主机(Ubuntu 系统)WiFi 抓包环境配置教程
ubuntu·wireshark
jinlei20092 小时前
配置ssh服务-ubuntu到Windows拷贝文件方法
运维·ubuntu·ssh