栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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版本
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/665913.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号