1. yum update -y
  2. yum upgrade -y

1、下载python版本 https://www.python.org/downloads/source/

2、 解压 tar -zxvf Python-3.6.5.tgz

3、进入python目录 cd Python-3.6.5

4、配置

  1. ./configure --prefix=/usr/local/python36
  1. make && make install
  2. make clean
  3. make distclean

5、建立软连接

  1. ln -s /usr/local/python36/bin/python3.6 /usr/bin/python3
  2. ln -s /usr/local/python36/bin/pip3 /usr/bin/pip3

问题一: can’t decompress data; zlib not available 解决方案: 1、安装相关的依赖,sqlite3问题

  1. yum -y install zlib zlib-devel
  2. yum -y install sqlite3-devel

2、重新编译python

  1. make install

问题二:

  1. pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
  1. #> python3
  2. Python 3.6.5 (default, Apr 25 2018, 17:00:02)
  3. [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import ssl
  6. Traceback (most recent call last):
  7. File "<stdin>", line 1, in <module>
  8. File "/usr/local/lib/python3.6/ssl.py", line 101, in <module>
  9. import _ssl # if we can't import it, let the error propagate
  10. ModuleNotFoundError: No module named '_ssl'

解决方案: 1、查看openssl安装包

  1. [root@localhost ~]# rpm -aq|grep openssl

2、如果缺少openssl包安装

  1. [root@localhost ~]# yum install openssl-devel -y

3、重新编译

  1. ./configure --with-ssl
  2. make
  3. make install

4、进入python3检查import ssl是否正常