本地开发升级成了py3.10.6,服务器测试时安装py3.10.4 发现无法正常使用pip3
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
印象中py3的高版本依赖高版本的openssl,centos 7下默认的openssl为1.0.x,
问题很简单,升级openssl,期间各种奇葩问题.包括但不限于修改setup配置等等
最后附上整理好的解决办法
# -*- encoding: utf-8 -*-
"""
@File : script.py
@Time : 2023/10/20 1:30
@Author : Perry
@Email : [email protected]
@Software: PyCharm
"""
import subprocess
def cmd_call(cmd):
for i in cmd:
print('*' * 10, i)
subprocess.call(i, shell=True)
def install_python310():
cmd = [
r'rm -rf Python-3.10.6.tgz',
r'rm -rf Python-3.10.6',
r'wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz',
r'tar -zxvf Python-3.10.6.tgz',
r'cd Python-3.10.6 && ./configure --prefix=/usr/local/python3 -with-openssl=/usr/local/openssl && make && make install',
r'rm -rf /usr/bin/python3 && rm -rf /usr/bin/pip3',
r'cd /usr/bin/ && ln -s /usr/local/python3/bin/python3 python3 && ln -s /usr/local/python3/bin/pip3 pip3',
]
cmd_call(cmd)
def install_openssl():
cmd = [
r'wget https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1q.tar.gz',
r'tar -zxvf openssl-OpenSSL_1_1_1q',
r'cd openssl-OpenSSL_1_1_1q',
r'./config --prefix=/usr/local/openssl shared zlib ',
r'make && make install ',
r'rm -rf /usr/bin/openssl',
r'rm -rf /usr/include/openssl',
r'rm -rf /usr/lib64/libssl.so',
r'rm -rf /usr/lib64/libcrypto.so',
r'ln -s /usr/local/openssl/include/openssl /usr/include/openssl',
r'ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl',
r'ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so',
r'ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so',
r'ldconfig'
]
cmd_call(cmd)
def update():
'''
有重复命令
:return:
'''
cmd = [
r'cd /root',
r'yum -y upgrade ',
r'yum -y install wget',
r'yum -y install gcc gcc-c++',
r'yum -y install perl zlib-devel bzip2 bzip2-devel openssl-devel ncurses-devel readline-devel tk-devel gdbm-devel '
r'db4-devel libpcap-devel xz-devel',
r"yum install -y libcurl-devel wget tar gcc make zip unzip openssl openssl-devel gcc libxml2 libxml2-devel libxslt* zlib zlib-devel libjpeg-devel libpng-devel libwebp libwebp-devel freetype freetype-devel lsof pcre pcre-devel vixie-cron crontabs icu libicu-devel c-ares libffi-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel",
r"yum install -y wget curl libcurl4-openssl-dev gcc make zip unzip tar openssl libssl-dev gcc libxml2 libxml2-dev zlib1g zlib1g-dev libjpeg-dev libpng-dev lsof libpcre3 libpcre3-dev cron net-tools swig build-essential libffi-dev libbz2-dev libncurses-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libdb++-dev libpcap-dev xz-utils git",
r'yum install -y libXext libSM libXrender ',
]
cmd_call(cmd)
def main():
update()
install_openssl()
install_python310()
if __name__ == '__main__':
main()