python 'cannot import name ' code example

Example 1: importerror: cannot import name

# While you should definitely avoid circular dependencies,
# you can defer imports in python.
# for example:

import SomeModule

def someFunction(arg):
    from some.dependency import DependentClass
    
#this ( at least in some instances ) will circumvent the error.

Example 2: importerror: cannot import name

Search your entire project/solution (generally ctrl-shift-f) for 'flask' or whatever the name import error is.
You may have it being imported twice and just need to remove one.

Tags: