Although there are a number of import related questions, I haven’t found one that directly addresses my question.
I have installed some packages in the default Site Packages
folder and it has a structure similar to this…
Site Packages
|--packageA
|----_init_.py
|----sub-packageB
|------_init_.py
|------fileB1.py
|----sub-packageC
|------_init_.py
|------fileC1.py
The site packages folder is added to the module search path automatically.
Now in fileB1.py
, if I call import sub-packageB
, I get a no module named sub-packageB
error. I know I can do from packageA import sub-packageB
.
So my question is: does the folder containing the first module/package mentioned in an import statement be explicitly referenced in the module search path? e.g. (1) if I have import sub-packageB
, should path to folder sub-packageB
be explicitly on module search path (2) if I have from sub-packageC import fileC1
, should path to folder sub-packageC
be explicitly on module search path (3) if I have import packageA.sub-packageB
, should path to folder packageA
be explicitly on module search path?
Thanks.
4