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
相关推荐
岑梓铭1 分钟前
(CentOs系统虚拟机)Standalone模式下安装部署“基于Python编写”的Spark框架
linux·python·spark·centos
丰色木夕14 分钟前
Ubuntu下的tcl/tk编程快速入门
ubuntu·tcl·tk
游客52016 分钟前
opencv中的各种滤波器简介
图像处理·人工智能·python·opencv·计算机视觉
Eric.Lee202118 分钟前
moviepy将图片序列制作成视频并加载字幕 - python 实现
开发语言·python·音视频·moviepy·字幕视频合成·图像制作为视频
Dontla23 分钟前
vscode怎么设置anaconda python解释器(anaconda解释器、vscode解释器)
ide·vscode·python
waicsdn_haha32 分钟前
Java/JDK下载、安装及环境配置超详细教程【Windows10、macOS和Linux图文详解】
java·运维·服务器·开发语言·windows·后端·jdk
大妞40 分钟前
ubuntu20.04 install vscode[ROS]
ubuntu
qq_529025291 小时前
Torch.gather
python·深度学习·机器学习
数据小爬虫@1 小时前
如何高效利用Python爬虫按关键字搜索苏宁商品
开发语言·爬虫·python
ac.char1 小时前
在 Ubuntu 下使用 Tauri 打包 EXE 应用
linux·运维·ubuntu