Python
ImportError
dateutil
error handling
module not found

ImportError No module named dateutil.parser

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

ImportError: No module named dateutil.parser usually means one of three things: the python-dateutil package is not installed in the active environment, your script is running under a different interpreter than the one where it was installed, or a local file is shadowing the real package. The import itself is straightforward once the environment is correct. The hard part is usually identifying which Python environment your code is actually using.

The Correct Package and Import

The package you install is called python-dateutil, but the import path is dateutil.

Correct import:

python
1from dateutil import parser
2
3dt = parser.parse("2026-03-07 12:30")
4print(dt)

Or:

python
1import dateutil.parser
2
3dt = dateutil.parser.parse("2026-03-07 12:30")
4print(dt)

The error means Python could not resolve that import path in the current runtime.

Install the Package in the Right Environment

The standard fix is:

bash
python -m pip install python-dateutil

Using python -m pip is safer than calling plain pip because it ties the installation to a specific interpreter.

For example, if your project uses Python 3 explicitly:

bash
python3 -m pip install python-dateutil

If you are in a virtual environment, activate it first before running the install command.

Confirm Which Interpreter Is Running

A very common problem is that the package is installed, but not in the interpreter your script is using.

Check the interpreter path:

bash
python -c "import sys; print(sys.executable)"

Then check whether the package is installed there:

bash
python -m pip show python-dateutil

If those two commands do not line up with the environment your editor, test runner, or application launcher is using, the import error will persist.

Virtual Environment Mismatch

Suppose you installed python-dateutil globally but your app runs in a virtual environment. The global install will not help.

Typical workflow:

bash
1python -m venv .venv
2source .venv/bin/activate
3python -m pip install python-dateutil
4python app.py

If you are using an IDE, also make sure the IDE interpreter is the same .venv interpreter you just configured.

Watch for Local Module Shadowing

Another common cause is naming your own file or folder dateutil.py or dateutil/. That shadows the real installed package.

Problematic structure:

text
project/
  dateutil.py
  app.py

Then app.py may import your local file instead of the package you expected.

You can inspect where Python is resolving the module from:

python
import dateutil
print(dateutil.__file__)

If the path points to your project directory unexpectedly, rename the conflicting file or folder.

Verify the Import Interactively

Sometimes the quickest test is an interactive one-liner:

bash
python -c "from dateutil import parser; print(parser.parse('2026-03-07'))"

If that works, the package itself is fine and the remaining problem is probably how your application is launched.

Dependency Files Matter

If the package is needed by the project, add it to your dependency file rather than only installing it manually.

For example in requirements.txt:

text
python-dateutil

This keeps environments reproducible across machines, CI jobs, and deployments.

Example Failure Diagnosis

A practical diagnosis sequence is:

  1. check the import statement
  2. run python -m pip show python-dateutil
  3. print sys.executable
  4. inspect whether a local dateutil.py exists
  5. retry the import in a one-line command

That sequence usually narrows the issue quickly.

Common Pitfalls

The biggest mistake is installing the package with one interpreter and running the script with another. Another is forgetting that the package name is python-dateutil while the import name is dateutil. Developers also often overlook local files named dateutil.py that shadow the real package. Finally, IDE and notebook environments can use a different interpreter from the one your shell is using, which makes the problem look inconsistent.

Summary

  • Install python-dateutil, but import it as dateutil.
  • Use python -m pip so the package is installed into the interpreter you actually run.
  • Check virtual environments and IDE interpreter configuration.
  • Look for local files or folders that shadow the dateutil package.
  • Verify the import with a simple one-line test before debugging deeper.

Course illustration
Course illustration

All Rights Reserved.