Centos安装Python

1
2
yum update -y
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
2
3
make && make install
make clean
make distclean

5、建立软连接

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

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

1
yum -y install zlib zlib-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
2
3
4
5
6
7
8
9
10
#> python3
Python 3.6.5 (default, Apr 25 2018, 17:00:02)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/ssl.py", line 101, in <module>
import _ssl # if we can't import it, let the error propagate
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
2
3
./configure --with-ssl
make
make install

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

This blog is under a CC BY-NC-SA 3.0 Unported License
本文链接:https://blog.suixin.kim/2018/05/01/python-centos-install/