-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Description
Bug report
Bug description:
Bug Report: Inconsistent Import Error Between Direct Execution and Module Import
Description
A Python script containing the line:
from six.moves import configparserproduces two different ModuleNotFoundError messages depending on how it is executed.
-
When run directly:
ModuleNotFoundError: No module named 'six' -
When imported via another script:
ModuleNotFoundError: No module named 'six.moves'
Both scenarios use the exact same code, so this suggests inconsistent behavior in how Python handles imports in __main__ versus module import mode.
Steps to Reproduce
- Create a file named
test_import.py:
from six.moves import configparser- Run it directly:
python test_import.py
- Create another file named
runner.py:
import test_import- Run:
python runner.py
- Compare the error messages from both executions.
Expected Behavior
Python should produce consistent import error messages regardless of whether a module is run directly or imported.
Actual Behavior
Running directly reports:
ModuleNotFoundError: No module named 'six'
Importing through another script reports:
ModuleNotFoundError: No module named 'six.moves'
Environment
- Python version: (fill in)
- OS: Windows 10/11
- Installation method: (official installer / store / embeddable zip / etc.)
- No virtual environment active
Additional Notes
This issue appeared while debugging the gsutil tool bundled with another project.
Even after reinstalling all libraries, the inconsistent import error persists.
CPython versions tested on:
3.14
Operating systems tested on:
Windows