ubuntu 22.04 如果直接安装python3,装的是python3.10,但现在某外部程序依赖python3.8,所以需要另外安装。
不推荐方法
网上常见方法是add-apt-repository添加 ppa:deadsnakes 源,但这样会导致同时安装python3.8和python3.10,会同时安装一大堆不需要用到的包。
命令如下:文章来源:https://www.toymoban.com/news/detail-639743.html
# 这是不推荐的安装方法,更推荐后面的安装方法
# 因为安装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文章来源地址https://www.toymoban.com/news/detail-639743.html
# 推荐用这个方法,手动添加源,不用 add-apt-repository 命令添加源
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
到了这里,关于ubuntu 22.04安装python3.8的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!