I'm seeing different package handling behavior in python3 when I'm running something like python -m moduala.test
and python moduala/testa.py
. In the -m case imports for moduala.modualb.pkgx in testa.py work and in the other case they don't work.
python --version
# Python 3.6.9
mkdir -p testpyproj/pkga/pkgb
cd testpyproj/
touch pkga/__init__.py
touch pkga/pkgb/__init__.py
echo 'print("# python!")' >pkga/pkgb/modx.py
echo 'from pkga.pkgb import modx' > pkga/test.py
python -m pkga.test
# python!
python pkga/test.py
# Traceback (most recent call last):
# File "pkga/test.py", line 1, in <module>
# from pkga.pkgb import modx
# ImportError: No module named pkga.pkgb
From the man page I would expect these to be the same:
-m module-name Searches sys.path for the named module and runs the corresponding .py file as a script.
What is the difference between python -m and python [file] for loading modules and handling packages?
Why does the python [file] not find pkga.pkgb?