I am trying to understand import mechanism behind python but this piece of code gives error.
Here is my folder structure:
import_test
-calculator
..__init__.py
..operation.py
-lib
..__init__.py
..multiply.py
It is working when i ran on PyCharm IDE, but if i run from command line like
'py operation.py'(for now windows,for the next phase i will try on raspbian RPi)
i am getting module not found error! Tried many ways from forums on internet but still no progress.
multiply.py:
def multiplier(a,b):
return a + b
operation.py:
from lib.multiply import multiplier
print (multiplier(3,4))
lib/init.py:
from .multiply import multiplier
This is the output of my running:
File "operation.py", line 1, in <module>
from lib.multiply import multiplier
ModuleNotFoundError: No module named 'lib'
__init__.py
in the root directory(import_test
) as well – Halley__init__.py
(irrespective of whether it has any contents) to determine whether or not something counts as a module. – Nuskupython -vv operation.py
python will print lots of info include all possible places where it's looking for the modules. – Copter