0

I am importing a python file that resides in a local sub-folder. But I get the below error upon trying to import:

ImportError: cannot import name 'Conf' from 'subfolder.utils'

Does this error mean it cannot find the python file I am trying to import? Or does it mean the file I am trying to import has errors in it? How do I resolve this error?

My folder structure is:

src/   
  __init__.py
  main.py   
  subfolder/ 
    __init__.py 
    utils/  
      __init__.py
      conf.py  

main.py:

from subfolder.utils import Conf

conf.py:

class Conf:
   ....

*I am using python 3.6

sazr
  • 24,984
  • 66
  • 194
  • 362

1 Answers1

2

You need to mention the module name i.e. conf.py in the import.

So, you can effectively do from subfolder.utils.conf import Conf

Alternatively, you can import the Conf in utils/__init__.py and your imports should work just fine.

Nitin Pandey
  • 649
  • 1
  • 9
  • 27