packages.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:mbot 作者: michaelkuty 项目源码 文件源码
def check_package_exists(package, lib_dir):
    """Check if a package is installed globally or in lib_dir.
    Returns True when the requirement is met.
    Returns False when the package is not installed or doesn't meet req.
    """
    try:
        req = pkg_resources.Requirement.parse(package)
    except ValueError:
        # This is a zip file
        req = pkg_resources.Requirement.parse(urlparse(package).fragment)

    # Check packages from lib dir
    if lib_dir is not None:
        if any(dist in req for dist in
               pkg_resources.find_distributions(lib_dir)):
            return True

    # Check packages from global + virtual environment
    # pylint: disable=not-an-iterable
    return any(dist in req for dist in pkg_resources.working_set)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号