I am trying to import a module that imports a module. But that doesnt work. This is my folder hierarchy:
/Project/
-test.py
/recognizer/
-__init__.py
-tools.py
-feature_extraction.py
I am importing tools.py
inside of feature_extraction.py
. If I run the feature_extraction.py
it all works like it should. Now I want to import the feature_extraction.py
from the test.py
, but that doesnt work. I get this error ModuleNotFoundError: No module named 'tools'
.
Inside the test.py
I am importing like this from recognizer import feature_extraction
that works like it should I think. Inside of feature_extraction.py
I am importing just like this import tools
. This should work I think, but it doesnt.
2 Answers 2
You should do this way.
from . import tools
If you import tools
from feature_extraction.py
file. it will lookup main directory which test.py
lays.
try to import in feature_extraction tools like this: import recognizer.tools
from . import tools