[{"data":1,"prerenderedAt":1592},["ShallowReactive",2],{"doc-\u002Ferrors\u002Fattributeerror-module-has-no-attribute-fix":3},{"id":4,"title":5,"body":6,"description":1585,"extension":1586,"meta":1587,"navigation":87,"path":1588,"seo":1589,"stem":1590,"__hash__":1591},"content\u002Ferrors\u002Fattributeerror-module-has-no-attribute-fix.md","AttributeError: module has no attribute (Fix)",{"type":7,"value":8,"toc":1558},"minimark",[9,13,25,30,112,115,131,135,138,153,160,174,188,196,200,231,234,255,258,293,301,331,335,338,358,362,365,372,389,400,429,432,501,504,515,519,522,525,540,543,584,587,624,633,660,668,672,675,678,700,707,712,748,757,762,797,809,813,816,843,846,880,883,890,920,926,974,980,987,991,994,998,1032,1037,1041,1077,1085,1089,1126,1134,1137,1166,1172,1175,1179,1182,1185,1196,1199,1215,1218,1229,1233,1236,1280,1283,1335,1339,1342,1364,1368,1372,1375,1386,1390,1396,1398,1453,1456,1460,1463,1466,1476,1480,1486,1489,1500,1504,1544,1554],[10,11,5],"h1",{"id":12},"attributeerror-module-has-no-attribute-fix",[14,15,16,17,24],"p",{},"Fix the error ",[18,19,20],"strong",{},[21,22,23],"code",{},"AttributeError: module has no attribute"," by checking what module Python imported, whether the attribute name is correct, and whether your own file name is hiding the real module.",[26,27,29],"h2",{"id":28},"quick-fix","Quick fix",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","import math\nprint(math.sqrt(9))\n\n# Check what names the module actually has\nprint(dir(math))\n","python","",[21,38,39,52,82,89,96],{"__ignoreMap":36},[40,41,44,48],"span",{"class":42,"line":43},"line",1,[40,45,47],{"class":46},"sVHd0","import",[40,49,51],{"class":50},"su5hD"," math\n",[40,53,55,59,63,67,70,73,75,79],{"class":42,"line":54},2,[40,56,58],{"class":57},"sptTA","print",[40,60,62],{"class":61},"sP7_E","(",[40,64,66],{"class":65},"slqww","math",[40,68,69],{"class":61},".",[40,71,72],{"class":65},"sqrt",[40,74,62],{"class":61},[40,76,78],{"class":77},"srdBf","9",[40,80,81],{"class":61},"))\n",[40,83,85],{"class":42,"line":84},3,[40,86,88],{"emptyLinePlaceholder":87},true,"\n",[40,90,92],{"class":42,"line":91},4,[40,93,95],{"class":94},"sutJx","# Check what names the module actually has\n",[40,97,99,101,103,106,108,110],{"class":42,"line":98},5,[40,100,58],{"class":57},[40,102,62],{"class":61},[40,104,105],{"class":57},"dir",[40,107,62],{"class":61},[40,109,66],{"class":65},[40,111,81],{"class":61},[14,113,114],{},"If the attribute is missing, check:",[116,117,118,122,128],"ul",{},[119,120,121],"li",{},"the spelling",[119,123,124,125,127],{},"your ",[21,126,47],{}," statement",[119,129,130],{},"whether you named your own file the same as the module",[26,132,134],{"id":133},"what-this-error-means","What this error means",[14,136,137],{},"This error means:",[116,139,140,146],{},[119,141,142,143],{},"Python successfully imported a ",[18,144,145],{},"module",[119,147,148,149,152],{},"but Python could not find the ",[18,150,151],{},"attribute name"," you tried to use",[14,154,155,156,159],{},"In this error, an ",[18,157,158],{},"attribute"," can be:",[116,161,162,165,168,171],{},[119,163,164],{},"a function",[119,166,167],{},"a class",[119,169,170],{},"a variable",[119,172,173],{},"a submodule",[14,175,176,177,180,181,184,185,69],{},"So if you write something like ",[21,178,179],{},"module_name.some_name",", Python expects ",[21,182,183],{},"some_name"," to exist inside that module. If it does not, you get an ",[21,186,187],{},"AttributeError",[14,189,190,191,69],{},"If you want a deeper explanation of attributes on non-module objects, see ",[192,193,195],"a",{"href":194},"\u002Ferrors\u002Fattributeerror-object-has-no-attribute-fix","AttributeError: object has no attribute (Fix)",[26,197,199],{"id":198},"simple-example-that-causes-the-error","Simple example that causes the error",[31,201,203],{"className":33,"code":202,"language":35,"meta":36,"style":36},"import math\n\nprint(math.random())\n",[21,204,205,211,215],{"__ignoreMap":36},[40,206,207,209],{"class":42,"line":43},[40,208,47],{"class":46},[40,210,51],{"class":50},[40,212,213],{"class":42,"line":54},[40,214,88],{"emptyLinePlaceholder":87},[40,216,217,219,221,223,225,228],{"class":42,"line":84},[40,218,58],{"class":57},[40,220,62],{"class":61},[40,222,66],{"class":65},[40,224,69],{"class":61},[40,226,227],{"class":65},"random",[40,229,230],{"class":61},"())\n",[14,232,233],{},"This raises an error because:",[116,235,236,242],{},[119,237,238,239,241],{},"the ",[21,240,66],{}," module exists",[119,243,244,245,248,249,252,253],{},"but ",[21,246,247],{},"random()"," is ",[18,250,251],{},"not"," part of ",[21,254,66],{},[14,256,257],{},"You would see an error like this:",[31,259,261],{"className":33,"code":260,"language":35,"meta":36,"style":36},"AttributeError: module 'math' has no attribute 'random'\n",[21,262,263],{"__ignoreMap":36},[40,264,265,268,271,274,278,281,283,286,288,290],{"class":42,"line":43},[40,266,187],{"class":267},"sZMiF",[40,269,270],{"class":61},":",[40,272,273],{"class":50}," module ",[40,275,277],{"class":276},"sjJ54","'",[40,279,66],{"class":280},"s_sjI",[40,282,277],{"class":276},[40,284,285],{"class":50}," has no attribute ",[40,287,277],{"class":276},[40,289,227],{"class":280},[40,291,292],{"class":276},"'\n",[14,294,295,296,298,299,270],{},"The correct module here is ",[21,297,227],{},", not ",[21,300,66],{},[31,302,304],{"className":33,"code":303,"language":35,"meta":36,"style":36},"import random\n\nprint(random.random())\n",[21,305,306,313,317],{"__ignoreMap":36},[40,307,308,310],{"class":42,"line":43},[40,309,47],{"class":46},[40,311,312],{"class":50}," random\n",[40,314,315],{"class":42,"line":54},[40,316,88],{"emptyLinePlaceholder":87},[40,318,319,321,323,325,327,329],{"class":42,"line":84},[40,320,58],{"class":57},[40,322,62],{"class":61},[40,324,227],{"class":65},[40,326,69],{"class":61},[40,328,227],{"class":65},[40,330,230],{"class":61},[26,332,334],{"id":333},"most-common-causes","Most common causes",[14,336,337],{},"The most common reasons are:",[116,339,340,343,346,349,352,355],{},[119,341,342],{},"misspelled attribute name",[119,344,345],{},"using the wrong module",[119,347,348],{},"naming your own file the same as a standard library module",[119,350,351],{},"importing the module in a different way than expected",[119,353,354],{},"using code from a different Python version",[119,356,357],{},"trying to use a submodule without importing it correctly",[26,359,361],{"id":360},"fix-1-check-the-attribute-name","Fix 1: Check the attribute name",[14,363,364],{},"A very common cause is simply typing the wrong name.",[14,366,367,368,371],{},"Python is ",[18,369,370],{},"case-sensitive",", so these are different:",[116,373,374,379,384],{},[119,375,376],{},[21,377,378],{},"math.sqrt",[119,380,381],{},[21,382,383],{},"math.Sqrt",[119,385,386],{},[21,387,388],{},"math.SQRT",[14,390,391,392,399],{},"Use ",[192,393,395,398],{"href":394},"\u002Freference\u002Fpython-dir-function-explained",[21,396,397],{},"dir()"," explained"," to see what names a module really has.",[31,401,403],{"className":33,"code":402,"language":35,"meta":36,"style":36},"import math\n\nprint(dir(math))\n",[21,404,405,411,415],{"__ignoreMap":36},[40,406,407,409],{"class":42,"line":43},[40,408,47],{"class":46},[40,410,51],{"class":50},[40,412,413],{"class":42,"line":54},[40,414,88],{"emptyLinePlaceholder":87},[40,416,417,419,421,423,425,427],{"class":42,"line":84},[40,418,58],{"class":57},[40,420,62],{"class":61},[40,422,105],{"class":57},[40,424,62],{"class":61},[40,426,66],{"class":65},[40,428,81],{"class":61},[14,430,431],{},"If you are looking for a specific name:",[31,433,435],{"className":33,"code":434,"language":35,"meta":36,"style":36},"import math\n\nprint(\"sqrt\" in dir(math))     # True\nprint(\"random\" in dir(math))   # False\n",[21,436,437,443,447,476],{"__ignoreMap":36},[40,438,439,441],{"class":42,"line":43},[40,440,47],{"class":46},[40,442,51],{"class":50},[40,444,445],{"class":42,"line":54},[40,446,88],{"emptyLinePlaceholder":87},[40,448,449,451,453,456,458,460,463,466,468,470,473],{"class":42,"line":84},[40,450,58],{"class":57},[40,452,62],{"class":61},[40,454,455],{"class":276},"\"",[40,457,72],{"class":280},[40,459,455],{"class":276},[40,461,462],{"class":46}," in",[40,464,465],{"class":57}," dir",[40,467,62],{"class":61},[40,469,66],{"class":65},[40,471,472],{"class":61},"))",[40,474,475],{"class":94},"     # True\n",[40,477,478,480,482,484,486,488,490,492,494,496,498],{"class":42,"line":91},[40,479,58],{"class":57},[40,481,62],{"class":61},[40,483,455],{"class":276},[40,485,227],{"class":280},[40,487,455],{"class":276},[40,489,462],{"class":46},[40,491,465],{"class":57},[40,493,62],{"class":61},[40,495,66],{"class":65},[40,497,472],{"class":61},[40,499,500],{"class":94},"   # False\n",[14,502,503],{},"This helps you quickly spot:",[116,505,506,509,512],{},[119,507,508],{},"spelling mistakes",[119,510,511],{},"wrong capitalization",[119,513,514],{},"names that do not exist in that module",[26,516,518],{"id":517},"fix-2-make-sure-you-imported-the-correct-module","Fix 2: Make sure you imported the correct module",[14,520,521],{},"Beginners often expect a function to be in one module when it actually belongs to another.",[14,523,524],{},"Example:",[116,526,527,535],{},[119,528,529,532,533],{},[21,530,531],{},"random.randint()"," belongs to ",[21,534,227],{},[119,536,537,538],{},"not ",[21,539,66],{},[14,541,542],{},"Wrong:",[31,544,546],{"className":33,"code":545,"language":35,"meta":36,"style":36},"import math\n\nprint(math.randint(1, 10))\n",[21,547,548,554,558],{"__ignoreMap":36},[40,549,550,552],{"class":42,"line":43},[40,551,47],{"class":46},[40,553,51],{"class":50},[40,555,556],{"class":42,"line":54},[40,557,88],{"emptyLinePlaceholder":87},[40,559,560,562,564,566,568,571,573,576,579,582],{"class":42,"line":84},[40,561,58],{"class":57},[40,563,62],{"class":61},[40,565,66],{"class":65},[40,567,69],{"class":61},[40,569,570],{"class":65},"randint",[40,572,62],{"class":61},[40,574,575],{"class":77},"1",[40,577,578],{"class":61},",",[40,580,581],{"class":77}," 10",[40,583,81],{"class":61},[14,585,586],{},"Correct:",[31,588,590],{"className":33,"code":589,"language":35,"meta":36,"style":36},"import random\n\nprint(random.randint(1, 10))\n",[21,591,592,598,602],{"__ignoreMap":36},[40,593,594,596],{"class":42,"line":43},[40,595,47],{"class":46},[40,597,312],{"class":50},[40,599,600],{"class":42,"line":54},[40,601,88],{"emptyLinePlaceholder":87},[40,603,604,606,608,610,612,614,616,618,620,622],{"class":42,"line":84},[40,605,58],{"class":57},[40,607,62],{"class":61},[40,609,227],{"class":65},[40,611,69],{"class":61},[40,613,570],{"class":65},[40,615,62],{"class":61},[40,617,575],{"class":77},[40,619,578],{"class":61},[40,621,581],{"class":77},[40,623,81],{"class":61},[14,625,626,627,270],{},"If you are unsure what a module contains, use ",[192,628,630,398],{"href":629},"\u002Freference\u002Fpython-help-function-explained",[21,631,632],{},"help()",[31,634,636],{"className":33,"code":635,"language":35,"meta":36,"style":36},"import random\n\nhelp(random)\n",[21,637,638,644,648],{"__ignoreMap":36},[40,639,640,642],{"class":42,"line":43},[40,641,47],{"class":46},[40,643,312],{"class":50},[40,645,646],{"class":42,"line":54},[40,647,88],{"emptyLinePlaceholder":87},[40,649,650,653,655,657],{"class":42,"line":84},[40,651,652],{"class":57},"help",[40,654,62],{"class":61},[40,656,227],{"class":65},[40,658,659],{"class":61},")\n",[14,661,662,663,667],{},"You can also review ",[192,664,666],{"href":665},"\u002Fhow-to\u002Fhow-to-import-a-module-in-python","how to import a module in Python"," if import statements still feel confusing.",[26,669,671],{"id":670},"fix-3-check-for-file-naming-conflicts","Fix 3: Check for file naming conflicts",[14,673,674],{},"This is one of the most common beginner mistakes.",[14,676,677],{},"If your file is named something like:",[116,679,680,685,690,695],{},[119,681,682],{},[21,683,684],{},"random.py",[119,686,687],{},[21,688,689],{},"math.py",[119,691,692],{},[21,693,694],{},"json.py",[119,696,697],{},[21,698,699],{},"os.py",[14,701,702,703,706],{},"then Python may import ",[18,704,705],{},"your file"," instead of the real module.",[14,708,709,710,270],{},"For example, if your script is named ",[21,711,684],{},[31,713,714],{"className":33,"code":589,"language":35,"meta":36,"style":36},[21,715,716,722,726],{"__ignoreMap":36},[40,717,718,720],{"class":42,"line":43},[40,719,47],{"class":46},[40,721,312],{"class":50},[40,723,724],{"class":42,"line":54},[40,725,88],{"emptyLinePlaceholder":87},[40,727,728,730,732,734,736,738,740,742,744,746],{"class":42,"line":84},[40,729,58],{"class":57},[40,731,62],{"class":61},[40,733,227],{"class":65},[40,735,69],{"class":61},[40,737,570],{"class":65},[40,739,62],{"class":61},[40,741,575],{"class":77},[40,743,578],{"class":61},[40,745,581],{"class":77},[40,747,81],{"class":61},[14,749,750,751,753,754,756],{},"you may get an error because Python imported your own ",[21,752,684],{}," file, not the standard library ",[21,755,227],{}," module.",[758,759,761],"h3",{"id":760},"how-to-fix-it","How to fix it",[763,764,765,778,794],"ol",{},[119,766,767,768,771,772,774,775],{},"Rename your file",[769,770],"br",{},"\nExample: change ",[21,773,684],{}," to ",[21,776,777],{},"my_random_test.py",[119,779,780,781],{},"Delete cached files if they exist:",[116,782,783,788],{},[119,784,785],{},[21,786,787],{},"__pycache__\u002F",[119,789,790,793],{},[21,791,792],{},".pyc"," files",[119,795,796],{},"Run the script again",[14,798,799,800,804,805,69],{},"This problem is also related to import errors such as ",[192,801,803],{"href":802},"\u002Ferrors\u002Fimporterror-no-module-named-x-fix","ImportError: No module named X"," and ",[192,806,808],{"href":807},"\u002Ferrors\u002Fimporterror-cannot-import-name-fix","ImportError: cannot import name",[26,810,812],{"id":811},"fix-4-check-what-python-actually-imported","Fix 4: Check what Python actually imported",[14,814,815],{},"If you are not sure what Python imported, print the module itself.",[31,817,819],{"className":33,"code":818,"language":35,"meta":36,"style":36},"import json\n\nprint(json)\n",[21,820,821,828,832],{"__ignoreMap":36},[40,822,823,825],{"class":42,"line":43},[40,824,47],{"class":46},[40,826,827],{"class":50}," json\n",[40,829,830],{"class":42,"line":54},[40,831,88],{"emptyLinePlaceholder":87},[40,833,834,836,838,841],{"class":42,"line":84},[40,835,58],{"class":57},[40,837,62],{"class":61},[40,839,840],{"class":65},"json",[40,842,659],{"class":61},[14,844,845],{},"You might see output like:",[31,847,849],{"className":33,"code":848,"language":35,"meta":36,"style":36},"\u003Cmodule 'json' from '\u002FUsers\u002Fyou\u002Fproject\u002Fjson.py'>\n",[21,850,851],{"__ignoreMap":36},[40,852,853,857,860,862,864,866,869,872,875,877],{"class":42,"line":43},[40,854,856],{"class":855},"smGrS","\u003C",[40,858,859],{"class":50},"module ",[40,861,277],{"class":276},[40,863,840],{"class":280},[40,865,277],{"class":276},[40,867,868],{"class":46}," from",[40,870,871],{"class":276}," '",[40,873,874],{"class":280},"\u002FUsers\u002Fyou\u002Fproject\u002Fjson.py",[40,876,277],{"class":276},[40,878,879],{"class":855},">\n",[14,881,882],{},"If that path points to your project file, then your file is shadowing the real module.",[14,884,885,886,889],{},"You can also inspect ",[21,887,888],{},"__file__"," directly:",[31,891,893],{"className":33,"code":892,"language":35,"meta":36,"style":36},"import json\n\nprint(json.__file__)\n",[21,894,895,901,905],{"__ignoreMap":36},[40,896,897,899],{"class":42,"line":43},[40,898,47],{"class":46},[40,900,827],{"class":50},[40,902,903],{"class":42,"line":54},[40,904,88],{"emptyLinePlaceholder":87},[40,906,907,909,911,913,915,918],{"class":42,"line":84},[40,908,58],{"class":57},[40,910,62],{"class":61},[40,912,840],{"class":65},[40,914,69],{"class":61},[40,916,888],{"class":917},"s_hVV",[40,919,659],{"class":61},[14,921,922,923,925],{},"For some modules, ",[21,924,888],{}," may not exist, so a safer version is:",[31,927,929],{"className":33,"code":928,"language":35,"meta":36,"style":36},"import json\n\nprint(getattr(json, \"__file__\", \"built-in module\"))\n",[21,930,931,937,941],{"__ignoreMap":36},[40,932,933,935],{"class":42,"line":43},[40,934,47],{"class":46},[40,936,827],{"class":50},[40,938,939],{"class":42,"line":54},[40,940,88],{"emptyLinePlaceholder":87},[40,942,943,945,947,950,952,954,956,959,961,963,965,967,970,972],{"class":42,"line":84},[40,944,58],{"class":57},[40,946,62],{"class":61},[40,948,949],{"class":57},"getattr",[40,951,62],{"class":61},[40,953,840],{"class":65},[40,955,578],{"class":61},[40,957,958],{"class":276}," \"",[40,960,888],{"class":280},[40,962,455],{"class":276},[40,964,578],{"class":61},[40,966,958],{"class":276},[40,968,969],{"class":280},"built-in module",[40,971,455],{"class":276},[40,973,81],{"class":61},[14,975,976,977,69],{},"If the path is wrong, rename the conflicting file and remove ",[21,978,979],{},"__pycache__",[14,981,982,983,69],{},"If you want to understand why Python chooses one file over another, read ",[192,984,986],{"href":985},"\u002Flearn\u002Fhow-import-works-in-python","how import works in Python",[26,988,990],{"id":989},"fix-5-verify-your-import-style","Fix 5: Verify your import style",[14,992,993],{},"Different import styles give you access to names in different ways.",[758,995,997],{"id":996},"style-1-import-the-module","Style 1: Import the module",[31,999,1001],{"className":33,"code":1000,"language":35,"meta":36,"style":36},"import math\n\nprint(math.sqrt(16))\n",[21,1002,1003,1009,1013],{"__ignoreMap":36},[40,1004,1005,1007],{"class":42,"line":43},[40,1006,47],{"class":46},[40,1008,51],{"class":50},[40,1010,1011],{"class":42,"line":54},[40,1012,88],{"emptyLinePlaceholder":87},[40,1014,1015,1017,1019,1021,1023,1025,1027,1030],{"class":42,"line":84},[40,1016,58],{"class":57},[40,1018,62],{"class":61},[40,1020,66],{"class":65},[40,1022,69],{"class":61},[40,1024,72],{"class":65},[40,1026,62],{"class":61},[40,1028,1029],{"class":77},"16",[40,1031,81],{"class":61},[14,1033,1034,1035,69],{},"Here you must use ",[21,1036,378],{},[758,1038,1040],{"id":1039},"style-2-import-one-name-directly","Style 2: Import one name directly",[31,1042,1044],{"className":33,"code":1043,"language":35,"meta":36,"style":36},"from math import sqrt\n\nprint(sqrt(16))\n",[21,1045,1046,1059,1063],{"__ignoreMap":36},[40,1047,1048,1051,1054,1056],{"class":42,"line":43},[40,1049,1050],{"class":46},"from",[40,1052,1053],{"class":50}," math ",[40,1055,47],{"class":46},[40,1057,1058],{"class":50}," sqrt\n",[40,1060,1061],{"class":42,"line":54},[40,1062,88],{"emptyLinePlaceholder":87},[40,1064,1065,1067,1069,1071,1073,1075],{"class":42,"line":84},[40,1066,58],{"class":57},[40,1068,62],{"class":61},[40,1070,72],{"class":65},[40,1072,62],{"class":61},[40,1074,1029],{"class":77},[40,1076,81],{"class":61},[14,1078,1079,1080,1082,1083,69],{},"Here you use ",[21,1081,72],{}," directly, not ",[21,1084,378],{},[758,1086,1088],{"id":1087},"a-common-mistake","A common mistake",[31,1090,1092],{"className":33,"code":1091,"language":35,"meta":36,"style":36},"from math import sqrt\n\nprint(math.sqrt(16))\n",[21,1093,1094,1104,1108],{"__ignoreMap":36},[40,1095,1096,1098,1100,1102],{"class":42,"line":43},[40,1097,1050],{"class":46},[40,1099,1053],{"class":50},[40,1101,47],{"class":46},[40,1103,1058],{"class":50},[40,1105,1106],{"class":42,"line":54},[40,1107,88],{"emptyLinePlaceholder":87},[40,1109,1110,1112,1114,1116,1118,1120,1122,1124],{"class":42,"line":84},[40,1111,58],{"class":57},[40,1113,62],{"class":61},[40,1115,66],{"class":65},[40,1117,69],{"class":61},[40,1119,72],{"class":65},[40,1121,62],{"class":61},[40,1123,1029],{"class":77},[40,1125,81],{"class":61},[14,1127,1128,1129,1131,1132,69],{},"This fails because you did ",[18,1130,251],{}," import the name ",[21,1133,66],{},[14,1135,1136],{},"Another common mistake:",[31,1138,1140],{"className":33,"code":1139,"language":35,"meta":36,"style":36},"import math\n\nprint(sqrt(16))\n",[21,1141,1142,1148,1152],{"__ignoreMap":36},[40,1143,1144,1146],{"class":42,"line":43},[40,1145,47],{"class":46},[40,1147,51],{"class":50},[40,1149,1150],{"class":42,"line":54},[40,1151,88],{"emptyLinePlaceholder":87},[40,1153,1154,1156,1158,1160,1162,1164],{"class":42,"line":84},[40,1155,58],{"class":57},[40,1157,62],{"class":61},[40,1159,72],{"class":65},[40,1161,62],{"class":61},[40,1163,1029],{"class":77},[40,1165,81],{"class":61},[14,1167,1168,1169,1171],{},"This fails because you imported the module, not the name ",[21,1170,72],{}," directly.",[14,1173,1174],{},"Make sure the way you call the name matches the way you imported it.",[26,1176,1178],{"id":1177},"fix-6-check-python-version-differences","Fix 6: Check Python version differences",[14,1180,1181],{},"Sometimes the attribute exists only in a different Python version.",[14,1183,1184],{},"This can happen when:",[116,1186,1187,1190,1193],{},[119,1188,1189],{},"you copy code from an older tutorial",[119,1191,1192],{},"you follow documentation for a newer Python version",[119,1194,1195],{},"a package changed its API between versions",[14,1197,1198],{},"Check your version with:",[31,1200,1204],{"className":1201,"code":1202,"language":1203,"meta":36,"style":36},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","python --version\n","bash",[21,1205,1206],{"__ignoreMap":36},[40,1207,1208,1211],{"class":42,"line":43},[40,1209,35],{"class":1210},"sbgvK",[40,1212,1214],{"class":1213},"stzsN"," --version\n",[14,1216,1217],{},"If example code does not match your environment, compare:",[116,1219,1220,1223,1226],{},[119,1221,1222],{},"your Python version",[119,1224,1225],{},"the tutorial's Python version",[119,1227,1228],{},"the package version, if it is not part of the standard library",[26,1230,1232],{"id":1231},"debugging-steps-in-order","Debugging steps in order",[14,1234,1235],{},"When you see this error, go through these steps:",[763,1237,1238,1245,1250,1256,1262,1268,1271,1277],{},[119,1239,1240,1241,1244],{},"Read the exact ",[18,1242,1243],{},"module name"," in the error message",[119,1246,1240,1247,1249],{},[18,1248,151],{}," that Python could not find",[119,1251,1252,1253],{},"Run ",[21,1254,1255],{},"dir(module_name)",[119,1257,1258,1259],{},"Print ",[21,1260,1261],{},"module_name",[119,1263,1258,1264,1267],{},[21,1265,1266],{},"module_name.__file__"," if available",[119,1269,1270],{},"Look for local files with the same module name",[119,1272,1273,1274,1276],{},"Confirm that your ",[21,1275,47],{}," statement matches how you use the name",[119,1278,1279],{},"Check your Python version if needed",[14,1281,1282],{},"Here are some useful commands:",[31,1284,1286],{"className":1201,"code":1285,"language":1203,"meta":36,"style":36},"python --version\npython -c \"import math; print(dir(math))\"\npython -c \"import json; print(json)\"\npython -c \"import json; print(getattr(json, '__file__', 'built-in module'))\"\n",[21,1287,1288,1294,1309,1322],{"__ignoreMap":36},[40,1289,1290,1292],{"class":42,"line":43},[40,1291,35],{"class":1210},[40,1293,1214],{"class":1213},[40,1295,1296,1298,1301,1303,1306],{"class":42,"line":54},[40,1297,35],{"class":1210},[40,1299,1300],{"class":1213}," -c",[40,1302,958],{"class":276},[40,1304,1305],{"class":280},"import math; print(dir(math))",[40,1307,1308],{"class":276},"\"\n",[40,1310,1311,1313,1315,1317,1320],{"class":42,"line":84},[40,1312,35],{"class":1210},[40,1314,1300],{"class":1213},[40,1316,958],{"class":276},[40,1318,1319],{"class":280},"import json; print(json)",[40,1321,1308],{"class":276},[40,1323,1324,1326,1328,1330,1333],{"class":42,"line":91},[40,1325,35],{"class":1210},[40,1327,1300],{"class":1213},[40,1329,958],{"class":276},[40,1331,1332],{"class":280},"import json; print(getattr(json, '__file__', 'built-in module'))",[40,1334,1308],{"class":276},[26,1336,1338],{"id":1337},"common-mistakes","Common mistakes",[14,1340,1341],{},"These are the most common specific causes:",[116,1343,1344,1347,1350,1358,1361],{},[119,1345,1346],{},"Typing the wrong function or attribute name",[119,1348,1349],{},"Using the wrong module for that function",[119,1351,1352,1353,1355,1356],{},"Local file name conflicts such as ",[21,1354,694],{}," or ",[21,1357,684],{},[119,1359,1360],{},"Incorrect import style",[119,1362,1363],{},"Version mismatch between your Python install and example code",[26,1365,1367],{"id":1366},"faq","FAQ",[758,1369,1371],{"id":1370},"why-does-this-happen-even-though-i-installed-the-module","Why does this happen even though I installed the module?",[14,1373,1374],{},"The module may be installed correctly, but:",[116,1376,1377,1380,1383],{},[119,1378,1379],{},"the attribute name may be wrong",[119,1381,1382],{},"that attribute may not exist in your version",[119,1384,1385],{},"a local file with the same name may be hiding the real module",[758,1387,1389],{"id":1388},"how-do-i-know-whether-python-imported-the-wrong-file","How do I know whether Python imported the wrong file?",[14,1391,1392,1393,69],{},"Print the module object or ",[21,1394,1395],{},"module.__file__",[14,1397,524],{},[31,1399,1401],{"className":33,"code":1400,"language":35,"meta":36,"style":36},"import json\n\nprint(json)\nprint(getattr(json, \"__file__\", \"built-in module\"))\n",[21,1402,1403,1409,1413,1423],{"__ignoreMap":36},[40,1404,1405,1407],{"class":42,"line":43},[40,1406,47],{"class":46},[40,1408,827],{"class":50},[40,1410,1411],{"class":42,"line":54},[40,1412,88],{"emptyLinePlaceholder":87},[40,1414,1415,1417,1419,1421],{"class":42,"line":84},[40,1416,58],{"class":57},[40,1418,62],{"class":61},[40,1420,840],{"class":65},[40,1422,659],{"class":61},[40,1424,1425,1427,1429,1431,1433,1435,1437,1439,1441,1443,1445,1447,1449,1451],{"class":42,"line":91},[40,1426,58],{"class":57},[40,1428,62],{"class":61},[40,1430,949],{"class":57},[40,1432,62],{"class":61},[40,1434,840],{"class":65},[40,1436,578],{"class":61},[40,1438,958],{"class":276},[40,1440,888],{"class":280},[40,1442,455],{"class":276},[40,1444,578],{"class":61},[40,1446,958],{"class":276},[40,1448,969],{"class":280},[40,1450,455],{"class":276},[40,1452,81],{"class":61},[14,1454,1455],{},"If the path points to your project file, your file is shadowing the real module.",[758,1457,1459],{"id":1458},"what-is-an-attribute-in-this-error","What is an attribute in this error?",[14,1461,1462],{},"An attribute is a name inside an object.",[14,1464,1465],{},"For modules, an attribute can be:",[116,1467,1468,1470,1472,1474],{},[119,1469,164],{},[119,1471,170],{},[119,1473,167],{},[119,1475,173],{},[758,1477,1479],{"id":1478},"can-dir-help-fix-this-error","Can dir() help fix this error?",[14,1481,1482,1483,1485],{},"Yes. ",[21,1484,1255],{}," shows the names available on the module.",[14,1487,1488],{},"That helps you find:",[116,1490,1491,1494,1497],{},[119,1492,1493],{},"misspellings",[119,1495,1496],{},"wrong assumptions about the module",[119,1498,1499],{},"missing attributes",[26,1501,1503],{"id":1502},"see-also","See also",[116,1505,1506,1510,1515,1520,1525,1533,1539],{},[119,1507,1508],{},[192,1509,195],{"href":194},[119,1511,1512],{},[192,1513,1514],{"href":802},"ImportError: No module named X (Fix)",[119,1516,1517],{},[192,1518,1519],{"href":807},"ImportError: cannot import name (Fix)",[119,1521,1522],{},[192,1523,1524],{"href":985},"How import works in Python",[119,1526,1527],{},[192,1528,1529,1530,1532],{"href":394},"Python ",[21,1531,397],{}," function explained",[119,1534,1535],{},[192,1536,1529,1537,1532],{"href":629},[21,1538,632],{},[119,1540,1541],{},[192,1542,1543],{"href":665},"How to import a module in Python",[14,1545,1546,1547,804,1550,1553],{},"If you keep hitting this error, inspect the import step by step. Once you know ",[18,1548,1549],{},"what Python imported",[18,1551,1552],{},"what names that module really contains",", the fix is usually easy to find.",[1555,1556,1557],"style",{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .stzsN, html code.shiki .stzsN{--shiki-light:#91B859;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":36,"searchDepth":54,"depth":54,"links":1559},[1560,1561,1562,1563,1564,1565,1566,1569,1570,1575,1576,1577,1578,1584],{"id":28,"depth":54,"text":29},{"id":133,"depth":54,"text":134},{"id":198,"depth":54,"text":199},{"id":333,"depth":54,"text":334},{"id":360,"depth":54,"text":361},{"id":517,"depth":54,"text":518},{"id":670,"depth":54,"text":671,"children":1567},[1568],{"id":760,"depth":84,"text":761},{"id":811,"depth":54,"text":812},{"id":989,"depth":54,"text":990,"children":1571},[1572,1573,1574],{"id":996,"depth":84,"text":997},{"id":1039,"depth":84,"text":1040},{"id":1087,"depth":84,"text":1088},{"id":1177,"depth":54,"text":1178},{"id":1231,"depth":54,"text":1232},{"id":1337,"depth":54,"text":1338},{"id":1366,"depth":54,"text":1367,"children":1579},[1580,1581,1582,1583],{"id":1370,"depth":84,"text":1371},{"id":1388,"depth":84,"text":1389},{"id":1458,"depth":84,"text":1459},{"id":1478,"depth":84,"text":1479},{"id":1502,"depth":54,"text":1503},"Master attributeerror module has no attribute fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Fattributeerror-module-has-no-attribute-fix",{"title":5,"description":1585},"errors\u002Fattributeerror-module-has-no-attribute-fix","sJFANZcCTHCppFcZ45n3O72NTINIKP0uVUFhcuPzVNw",1777585478242]