202107281410 - 离线安装python3

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum -y install zlib*

tar -zxvf Python-3.6.6.tgz
chown -R root.root Python-3.6.6
cd Python-3.6.6
./configure --prefix=/usr/local/python3 --enable-shared --with-ssl
make && make install

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

cp libpython3.6m.so.1.0 /usr/lib64/

python3 -V


pip show requests

python3 ph.py

Traceback (most recent call last):
  File "ph.py", line 3, in <module>
    from pyhive import hive
  File "/data03/bonc_zj/.local/lib/python3.6/site-packages/pyhive/hive.py", line 15, in <module>
    from ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED, create_default_context
  File "/usr/local/python3/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'
rpm -aq|grep openssl
# 缺少openssl-devel
wget
ipm -ivh 
# 各种依赖被需要


#修改Setup文件

vi /root/Python-3.6.5/Modules/Setup.dist

#修改结果如下:

# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
 _ssl _ssl.c \
 -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
 -L$(SSL)/lib -lssl -lcrypto

升级openssl

no module named '_ssl'

# 查看ssl版本
openssl version -a

# python3。6 需要ssl 1.1以上,需要升级openssl

1、下载openssl-1.0.2h.tar.gz

wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz

2、更新zlib

yum install -y zlib

3、解压安装

tar zxf openssl-1.0.2h.tar.gz

cd openssl-1.0.2h

./config shared zlib

make && make install

mv /usr/bin/openssl /usr/bin/openssl.bak

mv /usr/include/openssl /usr/include/openssl.bak

ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl

ln -s /usr/local/ssl/include/openssl /usr/include/openssl

echo “/usr/local/ssl/lib” >> /etc/ld.so.conf

ldconfig -v

# 查看ssl版本 验证
openssl version -a

OK

posted @ 2025-03-19 21:59  钱塘江畔  阅读(33)  评论(0)    收藏  举报