Ubuntu16.04安装Python3.6及安装过程中错误解决

Ubuntu16.04默认安装了Python2.7和3.5

请注意,系统自带的python千万不能卸载!

输入命令python

Ubuntu16.04安装Python3.6及安装过程中错误解决

按Ctrl+D退出python命令行

Ubuntu16.04安装Python3.6及安装过程中错误解决

输入命令sudo add-apt-repository ppa:jonathonf/python-3.6

Ubuntu16.04安装Python3.6及安装过程中错误解决

Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success
'if /usr/bin/test -w /var/cache/app-info -a -e /usr/bin/appstreamcli;
 then appstreamcli refresh > /dev/null;
 fi'
E: Sub-process returned an error code

Ubuntu16.04安装Python3.6及安装过程中错误解决

在运行sudo apt-get update时出现如上信息,解决方法如下:

sudo pkill -KILL appstreamcli
wget -P /tmp https://launchpad.net/ubuntu/+archive/primary/+files/appstream_0.9.4-1ubuntu1_amd64.deb https://launchpad.net/ubuntu/+archive/primary/+files/libappstream3_0.9.4-1ubuntu1_amd64.deb
sudo dpkg -i /tmp/appstream_0.9.4-1ubuntu1_amd64.deb /tmp/libappstream3_0.9.4-1ubuntu1_amd64.deb

执行完上述命令之后再次运行sudo apt-get update就不会再出现上面的错误。

Ubuntu16.04安装Python3.6及安装过程中错误解决

按Enter确认

输入命令sudo apt-get update

输入命令sudo apt-get install python3.6

按Y确认

 

调整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

更改默认值,python默认为Python2,现在修改为Python3

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

 

此时再输入命令python

Ubuntu16.04安装Python3.6及安装过程中错误解决

可以看到此时已经是Python3.6了