【问题标题】:Error : pkg_resources.DistributionNotFound: The 'backports.functools-lru-cache' distribution was not found and is required by pylint错误:pkg_resources.DistributionNotFound:找不到“backports.functools-lru-cache”分发,pylint 需要它
【发布时间】:2016-11-23 12:42:17
【问题描述】:

我正在尝试运行 Pylint,但出现以下错误:

pkg_resources.DistributionNotFound:未找到“backports.functools-lru-cache”分布,pylint 需要该分布

我找到了以下链接,但不确定如何处理这些文件或将它们放在哪里。 https://pypi.python.org/simple/backports.functools-lru-cache/

我该如何解决这个问题?

【问题讨论】:

  • pylint 是哪个版本的?
  • 你是如何安装 pylint 的?
  • 我使用了 pip install pylint 命令

标签: python python-2.7 static-analysis pylint


【解决方案1】:

我遇到了同样的问题,我安装了两个缺少的依赖项(pylint 上的配置错误或未更新 pip??) 做吧:

pip install backports.functools_lru_cache

那么如果你收到如下错误:

raise DistributionNotFound(req)

pkg_resources.DistributionNotFound: configparser

只是做:

pip install configparser

【讨论】:

    【解决方案2】:

    据我所知,某些 RHEL/CentOS 版本的 yum 存储库中的 backports.ssl-match-hostname 包存在某种问题,这可能会在其他 backports 包从 PyPI 更新时导致问题。具体来说,在 RHEL7.2 环境中,我重现了如下问题:

    > yum install python-pip  # indirectly installs backports.ssl-match-hostname
    > pip2 install pylint     # indirectly installs backports.functools_lru_cache
    > pip2 install --upgrade backports.ssl-match-hostname  # install latest package from pypi, which effectively corrupts backports.functools_lru_cache
    > python2 -m pylint --version   # fails with missing import backports.functools_lru_cache
    

    我发现避免这种情况的唯一方法是将 yum 安装的软件包替换为 PyPI 中的等效软件包。这可以按如下方式完成:

    > yum install python-pip  # installs backports.ssl-match-hostname as a transitive dependency
    > pip2 freeze > temp_reqs.txt  # take a snapshot of the installed packages and versions
    > pip2 uninstall backports.ssl-match-hostname  # remove the yum installed package
    > pip2 install -r temp_reqs.txt  # reinstall the same version of the backports package, but install from PyPI
    

    现在安装的包应该可以正常工作了。执行以下测试用例证实了这一点:

    > pip2 install pylint
    > pip2 install --upgrade backports.ssl-match-hostname  # previously caused corruption of backports.functools_lru_cache used by pylint
    > python2 -m pylint --version  # now works correctly
    

    希望这可以帮助其他人解决这个问题。

    【讨论】:

    • 我在 OSX 下也遇到了这个问题。
    【解决方案3】:

    我在 CentOS 7 上的 virtual environment 中运行时遇到了这个问题。

    在 CentOS 上,backports 模块被打包为 yum 包 (python-backports.x86_64)。

    解决方案是使用 --system-site-packages 选项创建 virtualenv。

    首先验证 ``python-backports` 包是否已安装:

    yum list installed | grep python-backports

    然后创建/重新创建您的虚拟环境:

    virtualenv env --system-site-packages

    这允许 virtualenv 的 pylint 在安装时看到 backports 模块。

    然后在虚拟环境中安装pylint:

    env/bin/pip install pylint

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-26
      • 2016-09-12
      • 2016-11-29
      • 2019-05-12
      • 2018-10-11
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多