Command “python setup.py egg_info“ failed with error code 1 in /tmp/pip-build-wp7bhkqo/cryptography/
1. 升级 pip 和工具链 pip3 install --upgrade pip setuptools wheel # 2. 安装 Rust 构建支持 pip3 install setuptools-rust # 3. 安装 ansible(自动解决 cryptography) pip3 install ansible。
你遇到的错误是因为在安装 ansible
时,依赖包 cryptography
需要使用 setuptools_rust
来构建(尤其是较新版本的 cryptography
引入了 Rust 编译依赖),而你的环境中缺少这个模块。
🔍 错误关键信息
ModuleNotFoundError: No module named 'setuptools_rust'
这说明:cryptography
的构建需要 setuptools-rust
,但当前 Python 环境中没有安装它。
✅ 解决方案
✅ 步骤 1:升级 pip
、setuptools
和 wheel
pip3 install --upgrade pip setuptools wheel
⚠️ 虽然提示说“用非 root 更安全”,但在某些系统上(如 Jenkins 服务器),你可能仍需 root 权限安装。若允许,可加
--user
。
✅ 步骤 2:安装 setuptools-rust
pip3 install setuptools-rust
这将解决 No module named 'setuptools_rust'
的问题。
✅ 步骤 3:再安装 ansible
pip3 install ansible
此时 cryptography
应能正常构建并安装。
💡 可选:使用系统包管理器(更快、更稳定)
如果你不想编译 cryptography
,可以考虑使用系统预编译的包:
对于 CentOS/RHEL/Oracle Linux:
yum install -y python3-pip ansible
或使用 dnf
(较新版本):
dnf install -y python3-pip ansible
这些版本可能略旧,但无需编译,避免构建问题。
🛠️ 额外建议(避免源码编译)
如果你想避免从源码编译 cryptography
,可以指定安装带二进制的版本(即 wheel
):
pip3 install --only-binary=cryptography cryptography
然后安装 ansible:
pip3 install ansible
注意:
ansible-core
2.11.12 可能仍需要cryptography>=3.3
,建议网络良好时直接安装。
✅ 总结:推荐执行命令
# 1. 升级 pip 和工具链
pip3 install --upgrade pip setuptools wheel
# 2. 安装 Rust 构建支持
pip3 install setuptools-rust
# 3. 安装 ansible(自动解决 cryptography)
pip3 install ansible
📌 补充说明
cryptography>=3.4
开始引入了 Rust 依赖,用于更安全的加密操作。- 如果你无法安装 Rust 工具链(如
rustc
、cargo
),至少需要setuptools-rust
来支持构建。 - 在 CI/CD 环境(如 Jenkins)中,建议将这些依赖写入初始化脚本,避免重复出错。
执行完以上步骤后,ansible
应能成功安装。如果仍有问题,可提供 pip3 --version
和 python3 --version
信息进一步排查。
更多推荐
所有评论(0)