I have a module called nbemail.py and in this module I want to use the function package_post defined in the module main.py. I am using this statement:
from api.main import package_post
But I am getting this error:
ImportError: cannot import name package_post
I really don’t know why I am getting this error! I do have _init_.py files in the api directory (which contains the files nbemail.py and main.py) and I do have the function package_post defined in main.py.
Any idea to help fixing this problem?
I suspect you have a circular dependency error. Do you import
nbemailfrommainas well? If so, Python won’t be able to resolve the dependency. The best way to fix this is to move one of the imports into a function, so it doesn’t happen when the module is first imported.