I have a directory structure like this
conf
__init__.py
settings.py
abc.conf
def.conf
src
main.py
xyz.py
src I chose not to make a package but a regular folder.
I am trying to import the settings.py file in the main.py and executing the whole thing with the command python3 main.py
My import statement in main.py : import conf.settings
The error I'm getting is No module named conf.settings
and I can't get my head around it.
Is python failing to recognize conf as a package? Can packages contain files other than .py files (.conf files in my case)
When importing python search current directory and the
sys.path
. Since yourmain.py
is insrc
folder it cannot see theconf
package folder. Luckily you could updatesys.path
at runtime.So you could append
sys.path
frommain.py
before importingconf
module. Try following:The other way is to update PYTHONPATH directly and add path to your script root directory.