之前的装机文章有介绍用3.6更换3.5的操作,需要加ppa源的时候发现经常出现错误,索性采取了源码安装Python3.6。
下载地址:https://www.python.org/downloads/source/ 选择需要的版本,这里选择的是3.6.10的.xz包
下载到任何路径都可以,完成之后解压:
tar xJf Python-3.6.10.tar.xz
随后进入解压后的文件夹并配置、编译:
cd Python-3.6.10
./configure
make
sudo make install
至此,Python3.6.10已经成功安装,原先的Python3.5已经被覆盖掉了。终端输入python3即可看到输出的版本信息已经变成了3.6.10。
PS:后期使用过程中发现在matplotlib中无法使用show显示,提示UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. 原因就在于缺少tkinter这些依赖,所以需要补充依赖后重新编译python3。建议初次编译安装时就将依赖装好!(参考博客:https://blog.youkuaiyun.com/jeryjeryjery/article/details/78865362)
sudo apt-get install tcl-dev tk-dev python3-tk libbz2-dev
#cd to the Python source code folder
./configure --with-ssl //为了能正常使用pip,需要重新编译ssl
make
sudo make install