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

Ubuntu环境下pip损坏时,如何无pip安装cryptography 38.0.4?

解决pip损坏后降级cryptography至38.0.4的方案

第一步:找到cryptography的安装位置

先定位Python的site-packages目录(第三方库默认存放路径):

  • 运行命令直接查询:
    python -c "import site; print(site.getsitepackages())"
    
  • 如果因AttributeError无法执行上述命令,按系统找默认路径:
    • Windows:C:\PythonXX\Lib\site-packages(XX为Python版本号,比如3.9)
    • macOS/Linux:/usr/local/lib/pythonX.X/site-packages 或 ~/.local/lib/pythonX.X/site-packages
    • 虚拟环境下路径为:你的虚拟环境目录/venv/lib/pythonX.X/site-packages

第二步:清理损坏的cryptography文件

进入site-packages目录,删除以下内容:

  • cryptography 文件夹
  • cryptography-*.dist-info 文件夹(*代表当前安装的版本号)

第三步:修复pip(可选但优先)

如果pip完全无法运行,先修复pip:

python -m ensurepip --upgrade

或者强制重新安装pip:

python -m pip install --upgrade pip --force-reinstall

第四步:安装指定版本的cryptography

你下载的.whl文件不需要解压,直接用Python内置的pip模块安装:

python -m pip install /你下载的wheel文件路径/cryptography-38.0.4-xxx.whl --force-reinstall

如果pip仍报错,尝试用wheel模块直接安装(先确保wheel已安装,若未安装,运行python -m ensurepip install wheel):

python -m wheel install /你下载的wheel文件路径/cryptography-38.0.4-xxx.whl

第五步:验证结果

运行以下命令确认版本:

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

输出38.0.4即表示安装成功,此时pip应该能恢复正常使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 00:15:05