Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ModuleNotFoundError even though the Module is present

I am getting a ModuleNotFoundError for a module that exists. I have a __init__.py and imported sys but I am still getting a ModuleNotFoundError error on my django error.

My file structure:

|-my_app
   |-folder1
     |-__init__.py
     |-calc.py
   |-folder2
     |-__init__.py
     |-test.py

I want to import a function from test.py in calc.py. This is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import sys
from folder2.test import func1, func2

#my code

When I run this, I am getting this error:
ModuleNotFoundError: No module named 'folder2.test'

How can I fix this error?

>Solution :

test is in folder1, so folder2.test will look for folder1\folder2\test.py, which is why the error comes up. Try changing the import to ..folder2.test.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading