Ubuntu中安装python3.6踩坑

原来的阿里云服务器Ubuntu是python3.8版本,此处重新安装python3.6,遇到的坑,记录解决办法

安装的相关命令

一、更新
sudo apt-get update
二、安装python3.6(此处有坑,未安装的同学用第五步方法安装)
apt-get install software-properties-common
add-apt-repository ppa:jonathonf/python-3.6
apt-get update
apt-get install python3.6
三、执行add-apt-repository ppa:jonathonf/python-3.6时报错 403 Forbidden [IP: ~]

Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal InRelease
Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates InRelease
Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security InRelease
Hit:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal InRelease
Err:5 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu focal InRelease
403 Forbidden [IP: 91.189.95.83 80]
Reading package lists… Done
E: Failed to fetch http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu/dists/focal/InRelease 403 Forbidden [IP: 91.189.95.83 80]
E: The repository ‘http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu focal InRelease’ is not signed.
N: Updating from such a repository can’t be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

四、解决办法

进入/etc/apt/sources.list.d文件把有关python3.6文件,以list结尾的文件删除。或者修改为.bak结尾

root@iZuf6b77csetgh3jg7sw2tZ:~# cd /etc/apt/sources.list.d
root@iZuf6b77csetgh3jg7sw2tZ:/etc/apt/sources.list.d# ls
deadsnakes-ubuntu-ppa-focal.list deadsnakes-ubuntu-ppa-focal.list.save jonathonf-ubuntu-python-3_6-focal.list jonathonf-ubuntu-python-3_6-focal.list.save
root@iZuf6b77csetgh3jg7sw2tZ:/etc/apt/sources.list.d# sudo mv jonathonf-ubuntu-python-3_6-focal.list jonathonf-ubuntu-python-3_6-xenial.list.bak
root@iZuf6b77csetgh3jg7sw2tZ:/etc/apt/sources.list.d# ls
deadsnakes-ubuntu-ppa-focal.list deadsnakes-ubuntu-ppa-focal.list.save jonathonf-ubuntu-python-3_6-focal.list.save jonathonf-ubuntu-python-3_6-xenial.list.bak
root@iZuf6b77csetgh3jg7sw2tZ:/etc/apt/sources.list.d# sudo mv deadsnakes-ubuntu-ppa-focal.list deadsnakes-ubuntu-ppa-focal.list.bak

在进行,无报错

sudo apt-get update

root@iZuf6b77csetgh3jg7sw2tZ:/etc/apt/sources.list.d# cd ~
root@iZuf6b77csetgh3jg7sw2tZ:~# sudo apt-get update
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal InRelease
Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates InRelease
Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security InRelease
Reading package lists… Done

五、重新安装

查了其他大哥的方法,用sudo add-apt-repository ppa:deadsnakes/ppa成功安装

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
apt-get update
apt-get install python3.6
六、更新报错ModuleNotFoundError: No module named ‘apt_pkg’

root@iZuf6b77csetgh3jg7sw2tZ:/usr/lib/python3/dist-packages# sudo apt-get update
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal InRelease
Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates InRelease
Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security InRelease
Hit:4 http://repo.mysql.com/apt/ubuntu trusty InRelease
Hit:5 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal InRelease
Traceback (most recent call last):
File “/usr/lib/cnf-update-db”, line 8, in
from CommandNotFound.db.creator import DbCreator
File “/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py”, line 11, in
import apt_pkg
ModuleNotFoundError: No module named ‘apt_pkg’
Reading package lists… Done

七、解决办法

1.先将原来的Python apt模块进行删除:

sudo apt-get remove --purge python-apt

2.再将它删除:

sudo apt-get install -f -y python-apt

3.进入文件层:

cd /usr/lib/python3/dist-packages/

4.将它改变:

sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.cpython-36m-x86_64-linux-gnu.so

注,我这里原来的python版本是3.8,所以写为…cpython-38-x86_64-linux… ,具体自己的可以用ls查询
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值