ubuntu 22.04安装python3.8
ubuntu 22.04 如果直接安装python3,装的是python3.10,但现在某外部程序依赖python3.8,所以需要重新安装。
不推荐方法
网上常见方法是add-apt-repository添加 ppa:deadsnakes 源,但这样会导致同时安装python3.8和python3.10。可我不想有两个版本。
命令如下:
# 这是不推荐的安装方法,更推荐后面的安装方法
# 因为安装software-properties-common时会把python3.10安装上去,这样就存在两个python3的版本了
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install -y python3.8 libpython3.8-dev python3.8-dev python3.8-distutils
推荐方法
更推荐以下安装方法,不安装software-properties-common,直接添加ppa:deadsnakes/ppa
# 推荐用这个方法
sudo echo 'deb https://launchpad.proxy.ustclug.org/deadsnakes/ppa/ubuntu/ jammy main' >>/etc/apt/sources.list
sudo apt-get update
# 这时会有个报错提示:
# W: GPG error: https://launchpad.proxy.ustclug.org/deadsnakes/ppa/ubuntu jammy InRelease: The following signatures couldn't be verified because the public key is not available: # NO_PUBKEY BA6932366A755776
# E: The repository 'https://launchpad.proxy.ustclug.org/deadsnakes/ppa/ubuntu jammy InRelease' is not signed.
# 导入这个key,key的id从报错信息里拿
sudo apt install -y gnupg
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA6932366A755776
sudo apt-get update
sudo apt-get install -y python3.8 libpython3.8-dev python3.8-dev python3.8-distutils
# 安装 pip
wget https://bootstrap.pypa.io/get-pip.py
python3.8 get-pip.py
# 加下软链接
sudo ln -s /usr/bin/python3.8 /usr/bin/python3
sudo ln -s /usr/bin/python3.8 /usr/bin/python
# 设置下国内镜像源
sudo pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple
热门相关:冉冉心动 女社长明子的日本梦 未来兽世:买来的媳妇,不生崽 后福 异世修真邪君