I created 2 folder with same name in Pycharm. Main folder with dpsystem and sub folder is also dpsystem. Now when I am trying to import from sub folder by giving command from dpsystem import settings It is marking red to settings as it is thinking that I am calling main folder.
While I am giving command from dpsystem.dpsystem import settings
It is accepting it but in terminal it is throwing error dpsystem.dpsystem is not a module.
Please refer screenshots and reply.image attached
Thanks in advanceenter image description here
I was expecting that subfolder will be selected successfully
CodePudding user response:
From the image you sent, the first dpsystem folder is a mere folder because it doesn’t directly contain an __init__.py file in it but it simply contains packages and folders mixed. It is the second dpsystem folder that is a package here because it directly contains an __init__.py file.
If you want the first dpsystem folder to become a module, then add an __init__.py file directly in it.
CodePudding user response:
Try this:
from ..dpsystem import settings
