I have the following directory structure. And I'm in .
.
./ # current directory
__init__.py
module_1/
__init__.py
util
__init__.py # contains f1(), f2(), ...
test.py
The following python command works fine
python -c "from module_1.util import f1, f2"
Running in REPL works fine too.
Python 3.8.11 (default, Aug 6 2021, 09:57:55) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from module_1.util import f1, f2
>>>
However, execute the test.py got the error of ModuleNotFoundError: No module named 'module_1'
. test.py has only one line
from module_1.util import f1, f2
Run script:
(base) PS C:\Users\X\src> python .\module_1\test.py
Traceback (most recent call last):
File ".\module_1\test.py", line 1, in <module>
from module1.util import f1, f2
ModuleNotFoundError: No module named 'module_1'