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

Sage安装pycrypto时出现Crypto模块缺失及pip SSL报错问题

问题场景

Sage环境运行代码时抛出No module named 'Crypto'导入错误,常规处理方案为执行安装命令:

sage --pip install pycrypto

执行上述命令时触发SSL连接错误,无法完成包拉取安装,完整报错输出如下:

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pycrypto/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pycrypto/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pycrypto/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pycrypto/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pycrypto/
Could not fetch URL https://pypi.org/simple/pycrypto/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pycrypto/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement pycrypto (from versions: none)
ERROR: No matching distribution found for pycrypto
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
故障原因
  • 核心根因为Sage内置的Python运行环境未编译SSL模块,无法建立HTTPS连接访问PyPI源拉取安装包,和pycrypto包本身是否存在无关。
  • 额外说明:pycrypto已停止维护多年,存在已知安全漏洞,当前推荐使用其兼容维护分支pycryptodome,导入路径完全一致,原有代码无需修改即可正常运行。
修复步骤
  1. 先安装系统层面的OpenSSL依赖,根据自身操作系统执行对应命令:
    • Debian/Ubuntu系列发行版:
    sudo apt update && sudo apt install -y libssl-dev openssl
    
    • RHEL/CentOS/Fedora系列发行版:
    sudo dnf install -y openssl openssl-devel
    # CentOS 7版本将dnf替换为yum执行即可
    
    • macOS(Homebrew环境):
    brew install openssl
    
  2. 重新编译Sage内置的Python环境,使其识别到系统安装的OpenSSL依赖:
sage -i python3
  1. 编译完成后,执行命令安装兼容版加密库:
sage --pip install pycryptodome

若重新编译内置Python后仍报SSL模块缺失错误,可直接下载对应系统的Sage官方完整二进制安装包覆盖安装,默认预装全部依赖,不会出现SSL模块缺失问题。

  1. 安装完成后进入Sage交互环境,执行import Crypto验证,无报错即代表修复完成。

内容的提问来源于stack exchange,提问作者Luke

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 21:12:25