def _compare_version(package: str, op, version) -> bool:
    '\n    Compare package version with some requirements\n\n    >>> _compare_version("torch", operator.ge, "0.1")\n    True\n    '
    try:
        pkg = importlib.import_module(package)
    except (ModuleNotFoundError, DistributionNotFound):
        return False
    try:
        pkg_version = Version(pkg.__version__)
    except TypeError:
        return True
    return op(pkg_version, Version(version))
Compare package version with some requirements

>>> _compare_version("torch", operator.ge, "0.1")
True
def _compare_version(package: str, op, version) -> bool:
    '\n    Compare package version with some requirements\n\n    >>> _compare_version("torch", operator.ge, "0.1")\n    True\n    '
    try:
        pkg = importlib.import_module(package)
    except (ModuleNotFoundError, DistributionNotFound):
        return False
    try:
        pkg_version = Version(pkg.__version__)
    except TypeError:
        return True
    return op(pkg_version, Version(version))