My folder structure is as follows
./fff
├── __init__.py
├── fg
│ ├── __init__.py
│ └── settings
│ ├── __init__.py
│ └── settings.py
└── obng
└── test.py
I want to import the settings.py inside fg/settings as a module into the test.py
I have added the line
from ..fg.settings import settings
But when I run it, it gives me the following error
Traceback (most recent call last): File "/mnt/d/Repos/fff/obng/test.py", line 1, in from ..fg.settings import settings ImportError: attempted relative import with no known parent package
This style of relative importing is supported as per https://docs.python.org/3/reference/import.html#package-relative-imports
What am I doing wrong here?
test.py
, you can't import stuff fromfg
in a relative fashion. – Forthrightpython test.py
you can't usefrom ..
. But if you have another .py file underfff
andimport test
then that will work. – Quixotesys.path.insert('/mnt/d/Repos/fff/fg')
and thenimport fg.setting
– Quixote