{"record":{"id":"873d93a18c4414d2","repo":"mlflow/mlflow","slug":"could-not-find-python-version-that-matches-versio","errorCode":null,"errorMessage":"Could not find python version that matches {version_prefix}","messagePattern":"Could not find python version that matches (.+?)","errorType":"exception","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/utils/virtualenv.py","lineNumber":91,"sourceCode":"        return _DATABRICKS_PYENV_BIN_PATH\n    return shutil.which(\"pyenv\")\n\n\ndef _find_latest_installable_python_version(version_prefix):\n    \"\"\"\n    Find the latest installable python version that matches the given version prefix\n    from the output of `pyenv install --list`. For example, `version_prefix(\"3.8\")` returns '3.8.x'\n    where 'x' represents the latest micro version in 3.8.\n    \"\"\"\n    lines = _exec_cmd(\n        [_get_pyenv_bin_path(), \"install\", \"--list\"],\n        capture_output=True,\n        shell=is_windows(),\n    ).stdout.splitlines()\n    semantic_versions = filter(_SEMANTIC_VERSION_REGEX.match, map(str.strip, lines))\n    matched = [v for v in semantic_versions if v.startswith(version_prefix)]\n    if not matched:\n        raise MlflowException(f\"Could not find python version that matches {version_prefix}\")\n    return max(matched, key=Version)\n\n\ndef _install_python(version, pyenv_root=None, capture_output=False):\n    \"\"\"Installs a specified version of python with pyenv and returns a path to the installed python\n    binary.\n\n    Args:\n        version: Python version to install.\n        pyenv_root: The value of the \"PYENV_ROOT\" environment variable used when running\n            `pyenv install` which installs python in `{PYENV_ROOT}/versions/{version}`.\n        capture_output: Set the `capture_output` argument when calling `_exec_cmd`.\n\n    Returns:\n        Path to the installed python binary.\n    \"\"\"\n    version = (\n        version","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/utils/virtualenv.py#L73-L109","documentation":"MLflow uses pyenv to resolve the newest installed pyenv Python matching the model's requested version prefix (e.g. '3.10'); this error is raised when no pyenv-managed Python version matches the prefix. It means pyenv is available but no compatible version is installed (or listed).","triggerScenarios":"A model's MLmodel pyfunc.python_version (e.g. 3.11) has no corresponding pyenv-installed version: _install_python -> _find_latest_installable_python_version runs `pyenv install --list`, filters by _SEMANTIC_VERSION_REGEX and the prefix, and the matched list is empty.","commonSituations":"Only a few Python versions installed via pyenv while the model was logged with a different one; pyenv lists non-semantic versions (e.g. 3.10-dev, rc builds) that are filtered out; `pyenv install --list` output empty or truncated due to a stale pyenv; typo in python_version when logging the model.","solutions":["Run `pyenv install --list | grep '^  3\\.'` to see available versions, then install the matching one: `pyenv install 3.10.14` (use the exact minor the model requests).","If the requested version is no longer listed by pyenv, update pyenv (`pyenv update` or reinstall) so its version list is current.","Resave/re-log the model with a python_version that pyenv can satisfy, or omit python_version to use the current environment.","Verify `pyenv versions` output and that MLflow's `pyenv install --list` subprocess actually succeeds (PATH/permissions)."],"exampleFix":"# before\n# MLmodel: python_version: 3.11 (only 3.10.x installed in pyenv)\nMlflowException: Could not find python version that matches 3.11\n\n# after\n$ pyenv install 3.11.9\n$ mlflow models serve -m model_dir --env-manager virtualenv  # resolves 3.11.9","handlingStrategy":"validation","validationCode":"import subprocess\nprefix = \"3.10\"  # the model's python_version\nout = subprocess.run([\"pyenv\", \"install\", \"--list\"], capture_output=True, text=True).stdout\nimport re\nversions = [v for v in map(str.strip, out.splitlines()) if re.match(r\"^\\d+\\.\\d+\\.\\d+$\", v)]\nassert any(v.startswith(prefix) for v in versions), f\"pyenv has no {prefix}.x version installed/listed; run: pyenv install $(pyenv install --list | grep -F '{prefix}.' | tail -1)\"","typeGuard":null,"tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    mlflow.models.serve(model_uri, env_manager=\"virtualenv\")\nexcept MlflowException as e:\n    if \"Could not find python version\" in str(e):\n        # install the missing pyenv python or re-log the model with an available version\n        ...","preventionTips":["Pre-install the Python minor versions your models use via pyenv in golden images.","Keep pyenv updated so its installable-version list includes current releases.","Pin python_version consistently when logging models; avoid typos in the semver string.","Check `pyenv versions` before serving a model whose python_version differs from your interpreter."],"tags":["python","pyenv","version-mismatch","environment"],"backgroundTag":"required-version-not-found","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}