有以下三个python文件

module_1.py

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from module_2 import b

def a():
    pass

module_2.py

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from module_3 import c

def b():
    pass

module_3.py

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from module_1 import a

def c():
    pass

测试类:

test.py

#! /usr/bin/env python
# -*- coding: utf-8 -*-

from module_1 import a

if __name__ == '__main__':
    print 'ok'

运行结果:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\pydevd.py", line 1741, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\pydevd.py", line 1735, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\pydevd.py", line 1135, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:/Dev/PyCharm/python/test/test.py", line 5, in <module>
    from module_1 import a
  File "D:\Dev\PyCharm\python\test\module_1.py", line 3, in <module>
    from module_2 import b
  File "D:\Dev\PyCharm\python\test\module_2.py", line 4, in <module>
    from module_3 import c
  File "D:\Dev\PyCharm\python\test\module_3.py", line 4, in <module>
    from module_1 import a
ImportError: cannot import name a

总结:

异常栈可以看出,导入a->b->c->a,导致无法导入a。注意这里并不是找不到a,如果从python依赖路径去找原因,是找不到的。分析依赖关系,拆分合并模块,去掉不必要的导入即可解决,比如把module_1,module_2,module_3中依赖部分放在一起。