Skip to content

Centos安装Python以及解决相关问题

270 字小于 1 分钟

2024-12-01

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、配置

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

5、建立软连接

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、安装相关的依赖,sqlite3问题

yum -y install zlib zlib-devel
yum -y install sqlite3-devel

2、重新编译python

make install

问题二:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
#> 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安装包

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

2、如果缺少openssl包安装

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

3、重新编译

./configure --with-ssl
make
make install

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