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

Redhat Linux 7.9离线环境安装cryptography-40.0.2(Python3.11.3)遇阻

离线安装cryptography的解决方案

1. 优先使用预编译平台专属whl包

你遇到的联网问题本质是纯Python版whl安装时会触发Rust编译,需要拉取github和crates.io的资源。解决的最简方案是下载适配Redhat 7.9的预编译平台专属whl包,这类包已经完成Rust部分的编译,无需联网:

  • 找对应Python版本的包,比如Python3.8对应cryptography-<版本号>-cp38-cp38-manylinux_2_17_x86_64.whl(manylinux2014标准兼容RHEL7)
  • 直接执行安装:
    python -m pip install cryptography-<版本号>-cp3x-cp3x-manylinux_2_17_x86_64.whl
    

2. 强制离线编译的配置方案(仅当必须用纯Python whl时)

如果只能用纯Python whl,需要让Rust的cargo工具读取本地依赖:

  • 在联网机器上提前拉取所有Rust依赖:
    # 先安装同版本cryptography触发依赖下载
    python -m pip install cryptography --no-binary :all:
    # 找到cryptography的Rust项目目录(通常在虚拟环境的lib/pythonX.X/site-packages/cryptography/hazmat/bindings/_rust)
    cd /path/to/cryptography/hazmat/bindings/_rust
    # 导出所有依赖到vendor目录
    cargo vendor --vendor-dir ./vendor
    
  • 将导出的vendor目录、你已下载的crates.io-index一起传到离线服务器的同一目录,比如/opt/rust_offline_deps
  • 在离线服务器上设置环境变量,让cargo走本地资源:
    export CARGO_HOME=/opt/rust_offline_deps
    export CARGO_REGISTRIES_CRATES_IO_INDEX=file:///opt/rust_offline_deps/crates.io-index
    export CARGO_VENDOR_DIR=/opt/rust_offline_deps/vendor
    
  • 执行安装:
    python -m pip install cryptography*.whl
    

3. 验证安装结果

安装后执行以下命令确认成功:

python -c "import cryptography; print(cryptography.__version__)"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 23:03:09