2025, Oct 21 03:00
How to Fix Matplotlib ImportError About python-dateutil Version: Align pip with the Right Python venv
Fix the Matplotlib ImportError about outdated python-dateutil: activate venv and run py -m pip to install/upgrade python-dateutil in the right environment.
Matplotlib fails to import with an ImportError that claims an outdated dateutil is present, while pip show reports a recent python-dateutil version. This usually looks confusing on the surface but has a straightforward root cause: the package was installed into a different Python environment than the one running your script.
Minimal example that triggers the error
The issue surfaces as soon as Python tries to import matplotlib, so even a tiny script is enough to reproduce it.
from matplotlib import pyplot as charts
def app_start():
    return charts  # touching pyplot is enough to trigger the import chain
if __name__ == "__main__":
    app_start()
In this scenario Python raises an error similar to the following:
ImportError: Matplotlib requires dateutil>=2.7; you have 2.2
What’s actually going on
Matplotlib depends on python-dateutil with a minimum required version. The interpreter that runs your script discovers a different dateutil than the one you inspected with pip show. That happens when packages are installed into one interpreter or environment while code is executed with another interpreter or environment. Typical reasons include having multiple Python installations on the machine or installing into the global environment while running inside a venv, or vice versa. Attempting to install a package named dateutil won’t help either, as pip reports there is no matching distribution for that name, while the correct package is python-dateutil.
Fix: align pip with the interpreter and use your venv
The remedy is to install or upgrade python-dateutil inside the exact environment that executes your code. On Windows with PowerShell, activate the project’s virtual environment and invoke pip via the interpreter launcher so the right Python owns the installation.
cd C:\Users\kystepa2\Desktop\NEXTSY_PROJECT
venv\Scripts\activate
py -m pip install --upgrade python-dateutil
After that, re-run the same minimal script. The import will succeed because matplotlib now sees a compatible python-dateutil version in the active environment.
Working script after the fix
The application code itself doesn’t need changes; it’s the environment alignment that matters. Running the same code below in the activated venv works as intended.
from matplotlib import pyplot as charts
def app_start():
    return charts
if __name__ == "__main__":
    app_start()
Why this matters for everyday development
Using the wrong pip or skipping virtual environment activation can silently install dependencies into a different Python than the one that runs your program. The result is hard-to-debug mismatches: your shell shows the right package version, but the interpreter that executes the code imports an older one. Consistent environment hygiene prevents these discrepancies and keeps installs, imports, and runtime behavior in sync across local development and CI.
Takeaways
Always activate the intended venv before installing or running. Prefer invoking pip through the interpreter with py -m pip so installations land in the same Python that executes your code. If you see ImportError messages about dependency versions, assume an environment mismatch first and realign your shell, venv, and pip to the interpreter that runs the script. And if you’re tempted to install a package named dateutil, note that pip already showed there’s no matching distribution; the correct dependency for matplotlib is python-dateutil.
The article is based on a question from StackOverflow by Konstantin Stepanov and an answer by AlirezaAliz.