ubuntu16.04安装python3.6

1、配置软件仓库,因为python 3.6 新版没有发布到ubuntu的正式仓库中,咱们通过第3方仓库来做。在命令行中输入:

sudo add-apt-repository ppa:jonathonf/python-3.6

系统会提示输入密码

2、检查系统软件包并安装 python 3.6

sudo apt-get update

sudo apt-get install python3.6

3、查看python版本信息(现在在你的系统中已经有3个python版本了)

python -V

python2 -V

python3 -V

python3.6 -V

4、新安装的3.6版本需要输入 python3.6才能使用,那能不能配置我只输入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

sudo update-alternatives --config python3

5、最后,咱们确认一下

python3 -V



如果安装完出现

ModuleNotFoundError: No module named 'apt_pkg'

这是因为升级到python3.6导致python库的引用产生混乱

解决方法

先选择删除python-apt

apt-get remove --purge python-apt

安装python-apt

apt-get install -f -y python-apt

拷贝python3.5的apt-pkg*.so 名重名为python3.6的apt-pkg*.so

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

cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.cpython-36m-x86_64-linux-gnu.so

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。