Ubuntu16.04安装并切换到python3.6

Ubuntu16.04安装并切换到python3.6,第1张

Ubuntu16.04安装并切换到python3.6

注意,Ubuntu16.04默认安装了Python2.7和3.5,系统自带的python千万不可卸载!

1、python3.6安装命令
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6
2、sudo apt-get update步骤出错

执行sudo apt-get update可能会失败,尝试了多种解决办法,最终通过更换清华源解决问题:

  • 先备份sources.list :
    Step 1: cd /etc/apt/
    Step 2: sudo cp sources.list sources.list.bak
  • 编辑sources.list:
    Step 1: sudo gedit /etc/apt/sources.list(注:使用sudo vim /etc/apt/sources.list无法编辑,会提示只读文件)
    Step 2: 将sources.list更换为清华源:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

Step 3: 保存退出后更新源使其生效
更新源:sudo apt-get update
更新软件:sudo apt-get upgrade

3、调整Python3的优先级,使得3.6优先级较高
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
4、python2切换到python3
python --version    //查看当前python版本,假设现在是python2版本
echo alias python=python3 >> ~/.bashrc  //切换python默认版本类型为python3版本,从python3版本切换到python2版本只需要将命令中的3改为2
source ~/.bashrc   //令配置文件改动生效
python --version    //再次查看会发生已改为python3版本,且由于前面设置了python3.6优先级高于python3.5,此时的版本为python3.6版本

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5671181.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存