python cannot import name

Solutions on MaxInterview for python cannot import name by the best coders in the world

showing results for - "python cannot import name"
Amanda
27 Aug 2019
1# While you should definitely avoid circular dependencies,
2# you can defer imports in python.
3# for example:
4
5import SomeModule
6
7def someFunction(arg):
8    from some.dependency import DependentClass
9    
10#this ( at least in some instances ) will circumvent the error.
Rafael
19 Aug 2018
1if you encounter this error:
2
3ImportError: Cannot import name whatever
4
5with a python file called "whatever",
6then this may be cause by the following issues:
7	1. file "whatever" is not in the same folder as the current file.
8    	this means that you need to place file "whatever" inside
9        the same file that gave you the import error.
10    2. library/module "whatever" is not installed.
11    	if "whatever" is a third-party library/module,
12        then you need to install the library/module.
13        This is usually done with "pip install whatever",
14        but exceptions do exist that the command is not
15        the proper command to install "whatever"
16    3. if this file is in another folder, but you don't want to move it.
17    	in this case, you should add this at the top of your file:
18        	import sys
19			sys.path.append('path/to/file/whatever.py')
20        replace 'path/to/file' with the proper directory of "whatever.py"
21    4. you forgot to create "whatever.py"!
22    	well... just remember to do that before importing.
23
24This does not include all of the possibilities. Hope this helped :D
Jaya
08 Jul 2018
1import SomeModule
2
3def someFunction(arg):
4    from some.dependency import DependentClass
Amy
26 May 2019
1While you should definitely avoid circular dependencies, you can defer imports in python.
2
3for example:
4
5import SomeModule
6
7def someFunction(arg):
8    from some.dependency import DependentClass
9this ( at least in some instances ) will circumvent the error.
Paolo
27 Feb 2019
1This is a circular dependency. It can be solved without any structural modifications to the code. The problem occurs because in vector you demand that entity be made available for use immediately, and vice versa. The reason for this problem is that you asking to access the contents of the module before it is ready -- by using from x import y. This is essentially the same as
2
3import x
4y = x.y
5del x
6Python is able to detect circular dependencies and prevent the infinite loop of imports. Essentially all that happens is that an empty placeholder is created for the module (ie. it has no content). Once the circularly dependent modules are compiled it updates the imported module. This is works something like this.
7
8a = module() # import a
9
10# rest of module
11
12a.update_contents(real_a)
13For python to be able to work with circular dependencies you must use import x style only.
14
15import x
16class cls:
17    def __init__(self):
18        self.y = x.y
19Since you are no longer referring to the contents of the module at the top level, python can compile the module without actually having to access the contents of the circular dependency. By top level I mean lines that will be executed during compilation as opposed to the contents of functions (eg. y = x.y). Static or class variables accessing the module contents will also cause problems.
Triston
01 Jan 2017
1Search your entire project/solution (generally ctrl-shift-f) for 'flask' or whatever the name import error is.
2You may have it being imported twice and just need to remove one.
queries leading to this page
importerror 3a cannot import name c3 a7importerror 3a cannot import name 27naming 27 site 3astackoverflow comimporterror 3a cannot import name 27final 27importerror 3a cannot import name loop from tasksimporterror 3a cannot import name function in modulecannot importimporterror cannot import nameimporterror 3a cannot import name from teh module existsimporterror 3a cannot import name whichimport error cannot import name functionimporterror 3a cannot import name v2cannot import name 27prod 27from import 3a cannot import nameimporterror 3a cannot import name but i can find it therecannot import name 27 27importerror 3a cannot import name pythoneimport error can 27t import nameimporterror 3a cannot import name 27 pythonimporterror 3a cannot import name 27 python from other dfileimporterror 3a cannot import name 27moduletnc 27cant import name from file pythonpython 2 importerror cannot import nameimporterror 3a cannot import name includecant import name from pythoncannot import name loop from taskscannot import name from pythonpython importerror 3a cannot import name site 3astackoverflow compython module cannot import namecannot import name from another file in python errorfrom import cannot import namepyuthon cannot import errorcannot import name frompython class cannot import namecannot import name from name pythonpython mporterror 3a cannot import name 22importerror 3a cannot import name 27loop 27 from 27tasks 27 22importerror 3a cannot import name 27prod 27 22python 22 22cannot import name 22importerror cannot import name from cpython soimporterror 3a cannot import name 27function 27importerror 3a cannot import name pyton errorpython cant import name from fileimport error python cannot import nameimporterror 3a cannot import name 27test 27 site 3astackoverflow compython can not import name fromimport error cannot import name in pythonimporterror 3a cannot import name 27 27 from 27 27importerror 3a cannot import name 27item 27cannot import 7b 7d fromimporterror 3a cannot import name versionimport error cannot import name from local moduleimporterror 3a cannot import name 27 c 27 site 3astackoverflow comimporterror 3a cannot import name 27a 27 pythoncannot import namingpython importerror 3a cannot importimporterror 3a cannot import name 27class 27 from 27file 27cannot import name pathonimporterror 3a cannot import name 27 27 pythoncannot import name error from pythonpython import error cannot import name fromimporterror 3a cannot import name 27ok 27error can not import name in pythonimport error cannot import name pythonpython from name name import namecannot import name 22import error 22 pythonimporterror 3a cannot import name 27 27importerror 3a cannot import name 27network 27 site 3astackoverflow comcannot import name python classcannot import nanamecannot import from pythoncannot import name python errorpython cannot import name from modulepython import error cannot import namemicropython importerror 3a cannot import nameimporterror 3a cannot import name fromimport error cannot import name importerror 3a cannot import name 27importer 27importerror cannot import name 27webencodings 27 from 27pip vendor 27from import x cannot import name ximporterror 3a cannot import name 27move 27cannot import name pythoinimporterror 3a cannot import name pythonpython cannot import name from another fileimporterror cannot import name from pyd filecannot import name python localimporterror 3a cannot import name from python 3a cannot import name 27 27 from 27 27importerror 3a cannot import name 27filecontent 27python 27cannot import name 27importerror 3a cannot import name 27make 27 from partially initialized modulecannot import name 27v2importerror 3a cannot import name from pythonpython 2c importerror 3a cannot import name how to solve import error cannot import name cookiejar from dictimporterror cannot import name self in pythonpython cannot import namepython importerror cannot import nameimporterror 3a cannot import name 27read 27importerror 3a cannot import name 27v2 27cannot import nameimporterror 3a cannot import name functioncannot import name class from file while other imports work fineimporterror 3a cannot import namecannot import name in pythonhow to solve import error cannot import name cookiejar from dictcannot import in pythonimporterror cannot import name in pythonimport error cannot import name e2 80 9dproblem 22importerror 3a cannot import name 22 27ocspmode 27 22 fromcannot import name 27calcmodellist 27 from partially initialized moduleimporterror cannot import name fromimporterror 3a cannot import name 27data 27 from 27server 27cannot import name available methodpython error cannot import nameimporterror 3a cannot import name 27cannot import name fromfrom math import prod importerror 3a cannot import name 27prod 27python cant import nameimporterror 3a cannot import name from pythoncannot import file in python error 22importerror 3a cannot import name 22python cannot import name fromimporterror 3a cannot import name in pythonexception has occurred 3a importerror cannot import nameimporterror 3a cannot import name 27 27 from 27 27unable to import name from partially initialized moduleerror cannot importcannot import name 27file 27importerror 3a cannot import name 27print version 27 site 3astackoverflow compython cannot import fromimporterror cant import name 27 27 from cannot import name error pythonimporterror cannot import name djangopython method import name findimporterror cannot import name 27 27 from 27 27cannot import name 27order 27cannot import name modules pythonpython importerror 3a cannot import nameimport name cannot import pythoni can not import importerror 3a cannot import name 27zip data branch 27 from partially initialized module 27backups tasksimporterror 3a cannot import name 27self 27importerror 3a cannot import name 27users 27python cannotr import nameimporterror cannot import name pythonpython cannot import both fileimporterror 3a cannot import name 27ocspmode 27 fromcannot import name from modulecannot import name from file pythonerror in name of import script pythonimporterror cannot import name 27 27 from 27 27 cpython soimporterror 3a cannot import name 27args 27 from 27mimetypes 27cannot import name 27 27 from 27 27importerror 3a cannot import name 27i 27 fromimporterror 3a cannot import name cannot import name pythoncannot import name errorpython cannot import name