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
内容来源于网络如有侵权请私信删除
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!