源码安装python3.6.7

https://www.python.org/
https://www.python.org/downloads/

选择XZ compressed source tarball, 拷贝文件绝对路径链接, 用wget命令下载

$ cd
$ mkdir soft
$ cd soft
$ wget -c https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tar.xz
$ xz -d Python-3.6.7.tar.xz
$ tar -xvf Python-3.6.7.tar
$ cd Python-3.6.7
$ sudo yum install -y readline-devel libffi-devel
$ ./configure --prefix=/usr/local/python3.6 --with-ssl --enable-loadable-sqlite-extensions
$ make && sudo make install

其中, 在configure加入–with-ssl是使用ssl功能模块。

for centos:

$ sudo yum install -y readline-devel libffi-devel

for ubuntu:

$ sudo apt-get install -y build-essential openssl libssl-dev libreadline-dev libffi-dev libsqlite3-dev sqlite3

装好后,将 /usr/local/python3.6/bin 加入 PATH:

export PATH=/usr/local/python3.6/bin:$PATH

在/etc/profile或/etc/zsh/zprofile或/etc/zprofile中添加以上环境变量, 并source /etc/profile 或 source /etc/zsh/zprofile 或source /etc/zprofile 使环境变量全局所有用户生效

再在~/.zshrc后面追加source /etc/zsh/zprofile

在~/.zshrc文件新追加的内容如下:

source /etc/zsh/zprofile

if [ -f /usr/local/python3.6/bin/virtualenvwrapper.sh ]; then
    export WORKON_HOME=$HOME/.virtualenvs
    source /usr/local/python3.6/bin/virtualenvwrapper.sh
fi

检测python3.6.7是否安装成功:

$ python3
Python 3.6.7 (default, Oct 30 2018, 17:39:33) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> exit()