无sudo权限在CentOS7远程机重装带SSL支持的Python3.11
重装带SSL支持的Python 3.11(CentOS 7环境)
问题背景
编译安装Python 3.11后pip无法安装任何模块,报错:
WARNING: pip is configured with locations that require TLS/SSL, however, the SSL module in Python is not available.尝试执行
./configure --with-ssl时出现错误:configure: WARNING: unrecognized options: --with-ssl机器环境:CentOS Linux 7,OpenSSL版本为1.1.1k FIPS 25 Mar 2021
核心原因
Python 3.11的configure脚本中,指定OpenSSL路径的正确参数是--with-openssl=DIR,而非你之前用的--with-ssl,这是参数不被识别的直接原因。
具体重装步骤
安装编译依赖
先确保OpenSSL开发包及其他编译依赖已安装,执行:yum install -y openssl-devel bzip2-devel libffi-devel zlib-devel gcc make如果你是手动编译安装的OpenSSL(非系统默认路径),要确认对应路径下的头文件(include)和库文件(lib)都存在。
清理编译残留
进入Python 3.11的源码目录,清理之前的编译文件:make clean配置编译参数
根据你的OpenSSL安装情况选择对应命令:- 若OpenSSL是系统默认路径(通过yum安装的1.1.1k):
说明:./configure --prefix=/usr/local/python311 --with-openssl --with-openssl-rpath=auto--prefix指定Python的安装路径,可按需修改;--with-openssl会自动查找系统中的OpenSSL;--with-openssl-rpath=auto确保Python运行时能正确找到SSL库。 - 若OpenSSL是手动编译在自定义路径(比如
/usr/local/openssl):./configure --prefix=/usr/local/python311 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto
- 若OpenSSL是系统默认路径(通过yum安装的1.1.1k):
编译并安装
make -j$(nproc) # 用全部CPU核心加速编译 make altinstall用
altinstall而非install,避免覆盖系统默认的Python版本。验证SSL支持
运行新安装的Python,检查SSL模块是否正常:/usr/local/python311/bin/python3.11 -c "import ssl; print(ssl.OPENSSL_VERSION)"如果输出
OpenSSL 1.1.1k FIPS 25 Mar 2021,说明SSL模块配置成功,此时pip也能正常安装模块了。
内容的提问来源于stack exchange,提问作者brownser
相关产品推荐
相关产品推荐

