Skip to main content

Fixed: "Detected one or more mismatches between the model's dependencies and the current Python environment" in MLflow

· 9 min read
Jagdish Kumawat
Founder @ Dewiride

I upgraded a project's packages and then scored some sessions with a model I had logged before the upgrade. MLflow printed WARNING mlflow.utils.requirements_utils: Detected one or more mismatches between the model's dependencies and the current Python environment, with five packages one release apart. MLflow had pinned the project's whole lockfile into the model when it logged it; running the model in its own environment, built from those pins, fixed it.

What I Was Doing​

Between Parts 7 and 8 of the MLflow series, new releases of five small packages that MLflow depends on came out, and I keep the series' projects on the newest releases. So in the shopper project, a uv project on MLflow 3.18.0, I upgraded every package in the lockfile:

Terminal
uv lock --upgrade
Output
Resolved 95 packages in 952ms
Updated charset-normalizer v3.5.2 -> v3.5.3
Updated databricks-sdk v0.169.0 -> v0.171.0
Updated google-auth v2.63.0 -> v2.63.1
Updated packaging v26.3 -> v26.4
Updated wcwidth v0.9.4 -> v0.9.5

Then I scored three example sessions with the registered model in use, which was logged before the upgrade. The project's predict command loads it with mlflow.pyfunc.load_model:

Terminal
uv run predict --input examples/sessions.csv

What I Expected​

The three purchase probabilities, as the same command printed before the upgrade.

What I Got​

The probabilities, after a seven-line warning:

Output
2026/11/25 09:54:55 INFO shopper_purchase_prediction: Scoring with version 2 of shopper-purchase-prediction, the champion
2026/11/25 09:54:55 WARNING mlflow.utils.requirements_utils: Detected one or more mismatches between the model's dependencies and the current Python environment:
- charset-normalizer (current: 3.5.3, required: charset-normalizer==3.5.2)
- databricks-sdk (current: 0.171.0, required: databricks-sdk==0.169.0)
- google-auth (current: 2.63.1, required: google-auth==2.63.0)
- packaging (current: 26.4, required: packaging==26.3)
- wcwidth (current: 0.9.5, required: wcwidth==0.9.4)
To fix the mismatches, call `mlflow.pyfunc.get_model_dependencies(model_uri)` to fetch the model's environment and install dependencies using the resulting environment file.
session purchase_probability
1 0.8931
2 0.0009
3 0.0033

The predict command's output in a terminal: the line naming version 2 of shopper-purchase-prediction, MLflow's warning listing charset-normalizer, databricks-sdk, google-auth, packaging and wcwidth with current and required versions, then the three probabilities 0.8931, 0.0009 and 0.0033.

The five packages in the warning are exactly the five the upgrade changed, each one release apart.

What I Checked​

What the model asks for. Every MLflow model carries a requirements.txt. I downloaded the champion's with the MLflow command line, which reads the server's address from MLFLOW_TRACKING_URI:

Terminal
export MLFLOW_TRACKING_URI=http://127.0.0.1:8080
uv run mlflow artifacts download -u "models:/shopper-purchase-prediction@champion/requirements.txt" -d champion-env
Output
/Users/you/source/dewiride-shopper-purchase-prediction/champion-env/requirements.txt

It pins an exact version of every package the project had, the five from the warning among them:

champion-env/requirements.txt (excerpt)
charset-normalizer==3.5.2
databricks-sdk==0.169.0
google-auth==2.63.0
packaging==26.3
wcwidth==0.9.4

What the project has. uv reports the installed version of any package:

Terminal
uv pip show packaging
Output
Name: packaging
Version: 26.4
Location: /Users/you/source/dewiride-shopper-purchase-prediction/.venv/lib/python3.15/site-packages
Requires:
Required-by: matplotlib, mlflow-skinny, mlflow-tracing, skops

Where the pins come from. MLflow's model dependencies guide explains it for uv projects: "When you log a model, MLflow checks for a uv.lock and pyproject.toml in the current working directory. If both files exist and uv (version 0.6.10 or later) is installed, MLflow runs uv export to produce a pinned requirements list from the lockfile." It's meant to capture "the exact versions you locked and tested with". When mlflow.pyfunc.load_model loads a model, it compares those pins with what's installed and warns about every difference.

What the warning suggests. Installing the model's requirements into the project would put the five older versions back, and in a uv project it wouldn't last: the uv reference says of uv run that "When used in a project, the project environment will be created and updated before invoking the command", so the next uv run brings the environment back in line with uv.lock.

Why It Happens​

The model was logged with the project's lockfile of that day, and MLflow froze every version from it into the model's requirements. The upgrade moved the project five packages forward, so the project's environment no longer matches the environment the model was tested with, and MLflow says so each time it loads the model. Here the newer packages don't change the predictions, 0.8931, 0.0009 and 0.0033 in both environments, as After the Fix shows, but MLflow can't know that for every package.

The Fix​

Run the model in its own environment: mlflow models predict with --env-manager uv builds a separate environment from the model's requirements.txt and predicts there, so the model gets the exact versions it was logged with and the project keeps its newer ones. The command reads a file of sessions; examples/sessions.json holds the same three sessions in MLflow's dataframe_split format, as How to Predict with an MLflow Model from the Command Line shows:

Terminal
export MLFLOW_TRACKING_URI=http://127.0.0.1:8080
uv run mlflow models predict -m "models:/shopper-purchase-prediction@champion" -i examples/sessions.json -t json --env-manager uv

Or log a new version from the upgraded project​

A model logged after the upgrade records the new versions, so the project loads it without a warning. In a project with a registry workflow, that's a new model version, judged like any other before it replaces the one in use.

After the Fix​

Output (excerpt)
2026/11/25 09:55:30 INFO mlflow.utils.virtualenv: Creating a new environment in /var/folders/…/T/tmpevin8lqy/envs/virtualenv_envs/mlflow-217dc732b07a188e27ddccb998d5ceea5443dbf8 with python version 3.15.2 using uv
...
Installed 89 packages in 953ms
...
+ charset-normalizer==3.5.2
...
- packaging==26.4
+ packaging==26.3
...
{"predictions": [[0.10694143736565398, 0.893058562634346], [0.999142902134051, 0.0008570978659490101], [0.9966742334522005, 0.0033257665477994395]]}

The command's output in a terminal: MLflow creating a new environment with uv, Installed 89 packages, charset-normalizer 3.5.2 installed and packaging 26.4 swapped for 26.3, then the predictions as JSON pairs ending in 0.893, 0.0009 and 0.0033.

The new environment got charset-normalizer 3.5.2 and packaging 26.3, the model's own versions, and there's no warning in the output. The second number in each pair is the purchase probability: 0.8931, 0.0009 and 0.0033 rounded, the same as before.

Common Mistakes​

MistakeWhat happensDo this instead
Installing the model's requirements into the projectOlder packages come back, and uv run puts the lockfile's versions back anywayRun the model in its own environment
Holding the project's packages back to stop the warningThe project misses fixes, and the next model logs old versions tooUpgrade, and log a new model version when the model should move with it

Troubleshooting​

SymptomLikely causeFix
The warning lists packages one release apartThe project was upgraded after the model was loggedmlflow models predict --env-manager uv, or a new model version
mlflow artifacts download can't find the modelMLFLOW_TRACKING_URI isn't set in this terminalSet it, as in the tabs above

FAQ​

Is the warning an error?​

No: the model loads and predicts. It means the model is running with packages it wasn't tested with, which is worth knowing before it scores real data.

Why does the model pin packages it doesn't use?​

Because MLflow exports the whole lockfile of a uv project, including every package MLflow itself needs. The guide's section on uv shows how to change that, such as MLFLOW_UV_AUTO_DETECT=false to turn off the detection.

Conclusion​

The warning appeared because MLflow froze the project's whole uv.lock into the model's requirements.txt when it logged it, and an upgrade moved five of those packages forward. mlflow models predict --env-manager uv ran the model in an environment built from its own pins, with no warning and the same probabilities; logging a new version from the upgraded project is the way to move the model itself forward.

Additional Resources​