ultralytics/ultralytics · error · ModuleNotFoundError

{name}{required} is required, but {name}=={current} is curre

Error message

{name}{required} is required, but {name}=={current} is currently installed {msg}

What it means

Raised by the version-comparison branch of check_requirements() when an installed package is present but its version does not satisfy the required specifier (e.g. '>=1.8.0'). Each operator (==, !=, >=, <=, >, <) is evaluated against the installed version; on failure and hard=True a ModuleNotFoundError carrying the requirement string is raised. This guards against known-incompatible dependency versions at runtime.

Source

Thrown at ultralytics/utils/checks.py:397

        op, version = re.match(r"([^0-9]*)([\d.]+)", r).groups()  # split '>=22.04' -> ('>=', '22.04')
        if not op:
            op = ">="  # assume >= if no op passed
        v = parse_version(version)  # '1.2.3' -> (1, 2, 3)
        n = max(len(c), len(v))  # pad to equal length so 4-segment pins like '!=4.13.0.90' compare exactly
        cn, vn = c + (0,) * (n - len(c)), v + (0,) * (n - len(v))
        if (
            (op == "==" and cn != vn)
            or (op == "!=" and cn == vn)
            or (op == ">=" and not (cn >= vn))
            or (op == "<=" and not (cn <= vn))
            or (op == ">" and not (cn > vn))
            or (op == "<" and not (cn < vn))
        ):
            result = False
    if not result:
        warning = f"{name}{required} is required, but {name}=={current} is currently installed {msg}"
        if hard:
            raise ModuleNotFoundError(warning)  # assert version requirements met
        if verbose:
            LOGGER.warning(warning)
    return result


def check_latest_pypi_version(package_name="ultralytics"):
    """Return the latest version of a PyPI package without downloading or installing it.

    Args:
        package_name (str): The name of the package to find the latest version for.

    Returns:
        (str | None): The latest version of the package, or None if unavailable.
    """
    import requests  # scoped as slow import

    try:
        requests.packages.urllib3.disable_warnings()  # Disable the InsecureRequestWarning

View on GitHub (pinned to 0449ea011c)

Solutions

  1. Upgrade the offending package to satisfy the specifier: pip install -U 'package>=x.y'
  2. Check the exact mismatch from the message (name==current vs required) and align your pins
  3. For non-fatal probing use hard=False and handle the False return

Example fix

# before
# torch 1.7 installed
check_requirements('torch>=1.8.0', hard=True)  # ModuleNotFoundError

# after
pip install -U 'torch>=1.8.0'
# or soft-check:
ok = check_requirements('torch>=1.8.0', hard=False)
Defensive patterns

Strategy: validation

Validate before calling

from ultralytics.utils.checks import check_requirements

ok = check_requirements('torch>=1.8.0', hard=False, verbose=False)
if not ok:
    raise SystemExit('upgrade torch: pip install -U torch')

Type guard

def version_satisfies(name: str, spec: str) -> bool:
    """True if installed package meets spec, without raising."""
    from importlib import metadata
    from packaging.specifiers import SpecifierSet
    try:
        return metadata.version(name) in SpecifierSet(spec)
    except metadata.PackageNotFoundError:
        return False

Try / catch

try:
    <ultralytics call>
except ModuleNotFoundError as e:
    if 'is required, but' in str(e):
        print(f'version conflict: {e} — align your environment pins')
    raise

Prevention

When it happens

Trigger: check_requirements('torch>=1.8.0') with torch 1.7 installed; export paths requiring e.g. 'nvidia-modelopt[onnx]>=0.44'; triton version pins on Windows/Linux. Triggered whenever the parsed operator comparison fails for the current environment.

Common situations: Old torch/numpy installations in frozen enterprise environments; version drift after a partial upgrade; downgrading one package without updating its dependents.

Related errors


AI-assisted analysis of ultralytics/ultralytics@0449ea011c (2026-08-15). Data as JSON: /api/errors/c2d818eee2475ef0. Report an issue: GitHub.