main files and module import errors

file structure

Hi, I've been stuck on this problem a while, and all other questions around this issue on this site haven't helped fix the issue. In the main.py file, I'm trying to import the datastorer function which sits in the StoreData.py file. I've created empty _init_.py files in the project root, DataStore folder and also Calculations folder. I'm importing using :

from project.DataStore.StoreData import datastorer 

But always get the error

ModuleNotFoundError: No module named 'project.DataStore'.

I've tried adding

myDir = os.getcwd()
sys.path.append(myDir)

to the top of the file which wasn't successful. I'm wondering if it's something to do with the name of the file main. Although I need to keep this as the file name. If anyone has any ideas this would be great thank you!


Solution 1:

If you add your current folder to python path, then all you imports should not refer to project so try

from DataStore.StoreData import datastorer