You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无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
      
  • 编译并安装

    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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 00:43:14