Wednesday, 17 October 2018

python - ImportError: No module named

I have a project which has a folder structure like so:



project:
folder1:
__init__.py
file11.py
folder2:
__init__.py
file21.py
folder3:

__init__.py
file31.py
__init__.py
file1.py
file2.py
..


From the root of the project, I am able to import the files on same path




Example,



In file1.py, from file2 import 123 and from folder3.file31 import 456 works



In file21.py, import file1 works



My issue is triggered when I do this:



Example,




In file21.py, from folder3.file31 import xyz



This is throwing an error like ImportError: No module named folder3



All my __init__.py files are empty and make python believe they are packages. I do not understand why this is happening. I would like to know a solution for this and also some little insights on how it works.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...