{"record":{"id":"f477d7e81e8298c3","repo":"mlflow/mlflow","slug":"this-container-only-supports-models-with-the-pyfun","errorCode":null,"errorMessage":"This container only supports models with the PyFunc flavors.","messagePattern":"This container only supports models with the PyFunc flavors\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"mlflow/models/container/__init__.py","lineNumber":73,"sourceCode":"    elif cmd == \"train\":\n        _train()\n    else:\n        raise Exception(f\"Unrecognized command {cmd}, full args = {sys.argv}\")\n\n\ndef _serve(env_manager):\n    \"\"\"\n    Serve the model.\n\n    Read the MLmodel config, initialize the Conda environment if needed and start python server.\n    \"\"\"\n    model_config_path = os.path.join(MODEL_PATH, MLMODEL_FILE_NAME)\n    m = Model.load(model_config_path)\n\n    if pyfunc.FLAVOR_NAME in m.flavors:\n        _serve_pyfunc(m, env_manager)\n    else:\n        raise Exception(\"This container only supports models with the PyFunc flavors.\")\n\n\ndef _install_pyfunc_deps(model_path=None, install_mlflow=False, env_manager=em.VIRTUALENV):\n    \"\"\"\n    Creates a conda env for serving the model at the specified path and installs almost all serving\n    dependencies into the environment - MLflow is not installed as it's not available via conda.\n    \"\"\"\n    activate_cmd = _install_model_dependencies_to_env(model_path, env_manager) if model_path else []\n\n    # NB: install gunicorn[gevent] from pip rather than from conda because gunicorn is already\n    # dependency of mlflow on pip and we expect mlflow to be part of the environment.\n    server_deps = [\"gunicorn[gevent]\"]\n\n    install_server_deps = [f\"pip install {' '.join(server_deps)}\"]\n    if Popen([\"bash\", \"-c\", \" && \".join(activate_cmd + install_server_deps)]).wait() != 0:\n        raise Exception(\"Failed to install serving dependencies into the model environment.\")\n\n    # NB: If we don't use virtualenv or conda env, we don't need to install mlflow here as","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/models/container/__init__.py#L55-L91","documentation":"_serve loads the MLmodel file baked into the container and checks that the pyfunc flavor is present before serving. Containers built for pyfunc serving can only execute models exposing the python_function flavor; otherwise it raises an Exception stating the container only supports PyFunc flavors.","triggerScenarios":"docker run ... serve on a container built from a model whose MLmodel lacks the 'python_function' flavor — e.g. models saved with mlflow.<flavor>.save_model that don't produce pyfunc, or an MLmodel manually edited/pruned to drop pyfunc.","commonSituations":"Serving R or Java-flavored-only models in the pyfunc container; building images from MLflow 1.x artifacts loaded by newer tooling; models saved with only 'loader_module' pyfunc removed; mistakenly generating a dockerfile for a non-pyfunc-able model.","solutions":["Re-log/save the model so it includes the python_function flavor (use mlflow.pyfunc.log_model or a flavor that produces pyfunc, e.g. sklearn/tensorflow log_model).","Check the MLmodel file in the container (cat /opt/ml/model/MLmodel) and confirm a 'python_function' flavors entry exists.","For non-Python models, use a serving path appropriate to that flavor rather than the pyfunc container.","If using a custom pyfunc, ensure python_function flavor registration via mlflow.pyfunc.model/PythonModel and re-build the image."],"exampleFix":"// before\nmlflow.sklearn.save_model(sk_model, path)  # missing pyfunc if custom loader pruned flavors\n// after\nimport mlflow\nmlflow.pyfunc.log_model(artifact_path=\"model\", python_model=my_model)  # ensures python_function flavor, then rebuild image","handlingStrategy":"validation","validationCode":"import mlflow.models\ndef validate_pyfunc_flavor(model_uri: str):\n    m = mlflow.models.get_model_info(model_uri)\n    if \"python_function\" not in m.flavors:\n        raise ValueError(f\"Model {model_uri} lacks python_function flavor; container serving requires it\")","typeGuard":"def has_pyfunc_flavor(model_info) -> bool:\n    return \"python_function\" in model_info.flavors","tryCatchPattern":"import subprocess\np = subprocess.run([\"docker\", \"run\", image, \"serve\"], capture_output=True)\nif p.returncode != 0 and b\"only supports models with the PyFunc flavors\" in p.stdout + p.stderr:\n    raise RuntimeError(\"Rebuild the image from a model with a python_function flavor\")","preventionTips":["Check the MLmodel flavors section before building/serving containers","Log models via mlflow.pyfunc.log_model or flavors that emit pyfunc (sklearn, tensorflow, etc.)","Don't manually strip the python_function flavor from MLmodel","For R/Java-only models use flavor-appropriate serving, not the pyfunc container"],"tags":["docker","container","pyfunc","models"],"backgroundTag":"unsupported-model-flavor","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}