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

CentOS7服务器Certbot运行报错pkg_resources.DistributionNotFound:mock求解决

Certbot执行报错:pkg_resources.DistributionNotFound: mock(CentOS 7)

问题详情

在CentOS 7 VPS服务器上执行yum install certbot后,系统提示*Package certbot-1.11.0-2.el7.noarch already installed and latest version*,但运行certbot命令时出现以下错误栈:

Traceback (most recent call last):
  File "/usr/bin/certbot", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 3007, in <module>
    working_set.require(__requires__)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 728, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 626, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: mock

服务器已安装的mock相关包:

rpm -qa |grep mock
easymock2-2.5.2-12.el7.noarch
python2-mock-1.0.1-10.el7.noarch

解决步骤

方法1:修复python2-mock的pkg_resources注册

  • 卸载并重新安装python2-mock:
    yum remove -y python2-mock
    yum install -y python2-mock
    
  • 刷新Python资源缓存:
    python -m pkg_resources
    rm -rf /usr/lib/python2.7/site-packages/pkg_resources/__pycache__
    

方法2:通过pip强制重新安装mock

如果服务器已安装pip2,执行:

pip2 install mock --force-reinstall

方法3:重新安装Certbot及全部依赖

yum reinstall -y certbot

方法4:验证Certbot的Python版本关联

检查Certbot使用的Python版本:

head -n 1 /usr/bin/certbot

确保输出为#!/usr/bin/python或#!/usr/bin/python2,若指向Python 3,需修改为Python 2路径,或在Python 3环境中安装mock包。


内容的提问来源于stack exchange,提问作者Shaheel K Karuvattil

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 10:35:16