Ubuntu 16.04 源码安装Python-3.6.7

新装的Ubuntu16.04自带了python2.7和python3.5,但是我做的东西需要python3.6.7环境,所以需要装一个

网上推荐了好多使用ppa安装的,但是我添加ppa之后一直没反应,试了CA证书,-E等方法均无效,所以只能源码安装了,参考了:https://blog.csdn.net/Carina_Cao/article/details/90210626

下载python3.6.7源码压缩包:/ftp/python/3.6.7/

安装一些依赖:

sudo apt-get install gcc make zlib1g-dev

sudo apt-get install libbz2-dev

sudo apt-get install libsqlite3-dev

sudo apt-get install python3-dev libxml2-dev libffi-dev libssl-dev libxslt1-dev

下载好之后,开始安装:

tar -zxvf Python-3.6.7.tgz

sudo mv Python-3.6.7 /usr/local

cd /usr/local/Python-3.6.7

./configure

sudo make

sudo make install

之后会显示安装成功,但是到这一步还不行,需要把系统默认的python版本切换成刚刚安装的

查询python安装路径:

whereis python

python: /usr/bin/python3.5m /usr/bin/python3.5 /usr/bin/python2.7 /usr/bin/python3.5m-config /usr/bin/python /usr/bin/python3.5-config /usr/lib/python3.5 /usr/lib/python2.7 /etc/python3.5 /etc/python2.7 /etc/python /usr/local/bin/python3.6 /usr/local/bin/python3.6m /usr/local/bin/python3.6-config /usr/local/bin/python3.6m-config /usr/local/lib/python3.6 /usr/local/lib/python3.5 /usr/local/lib/python2.7 /usr/include/python3.5m /usr/include/python3.5 /usr/share/python /usr/share/man/man1/python.1.gz

加入已经安装的python:

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

sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.6 200

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

此时查询可配置的python:

update-alternatives --list python

会显示:

/usr/bin/python2.7

/usr/bin/python3.5

/usr/local/bin/python3.6

有于设置了优先级,此时系统的默认pyhont版本已经变成了python3.6.7,如果需要切换,可以输入:

update-alternatives --config python

会显示可配置的python:

有 3 个候选项可用于替换 python (提供 /usr/bin/python)。

  选择      路径                    优先级  状态

------------------------------------------------------------

* 0            /usr/local/bin/python3.6  200      自动模式

  1            /usr/bin/python2.7        100      手动模式

  2            /usr/bin/python3.5        150      手动模式

  3            /usr/local/bin/python3.6  200      手动模式

你可能感兴趣的:(Ubuntu 16.04 源码安装Python-3.6.7)