LinuxMint-21.1 python版本切换
LinuxMint-21.1默认安装的是python3.10,如果要用到需要的python版本是3.8则需要另外安装(LinuxMint-21.1并没有提供python3.8的源)。
安装方法如下:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.8
使用命令查看链接
ll /usr/bin/ | grep python
使用update-alternatives --install建立链接
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
后面还有一个数字,代表了优先级,数字越大优先级越高,这里设置python3.8优先级高点。
可以通过命令设置系统使用的python版本
sudo update-alternatives --config python
根据提示输入对应的数字即可。
执行sudo add-apt-repository ppa:deadsnakes/ppa可能遇到错误:
gpg: failed to create temporary file '/root/.gnupg/.#lk0x00005602663c0110.ufo-desktop.34986': 没有那个文件或目录
gpg: connecting dirmngr at '/root/.gnupg/S.dirmngr' failed: 没有那个文件或目录
gpg: 从公钥服务器接收失败:缺少 dirmngr
需要在/root/目录下创建.gnupg目录
mkdir .gnupg
重新执行
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update