[{"data":1,"prerenderedAt":1965},["ShallowReactive",2],{"doc-\u002Ferrors\u002Ftypeerror-module-object-is-not-callable-fix":3},{"id":4,"title":5,"body":6,"description":1958,"extension":1959,"meta":1960,"navigation":83,"path":1961,"seo":1962,"stem":1963,"__hash__":1964},"content\u002Ferrors\u002Ftypeerror-module-object-is-not-callable-fix.md","TypeError: 'module' object is not callable (Fix)",{"type":7,"value":8,"toc":1915},"minimark",[9,19,32,51,56,154,157,166,173,177,184,191,204,210,213,245,247,274,286,290,293,323,326,357,360,382,388,392,399,406,439,441,450,456,498,501,510,515,579,581,610,628,632,635,671,673,681,691,694,723,752,759,766,770,773,777,811,817,821,824,834,837,861,867,900,903,913,916,934,937,973,980,984,987,1011,1014,1036,1062,1088,1091,1120,1153,1186,1193,1197,1200,1204,1207,1222,1227,1230,1234,1237,1248,1251,1266,1269,1286,1290,1329,1332,1376,1382,1386,1416,1429,1433,1466,1470,1486,1489,1517,1520,1524,1530,1537,1540,1543,1585,1591,1597,1600,1602,1633,1639,1645,1649,1652,1676,1680,1683,1745,1748,1760,1764,1768,1771,1775,1784,1807,1811,1814,1818,1821,1828,1862,1866,1869,1873,1908,1911],[10,11,13,14,18],"h1",{"id":12},"typeerror-module-object-is-not-callable-fix","TypeError: ",[15,16,17],"code",{},"'module' object is not callable"," (Fix)",[20,21,22,23,27,28,31],"p",{},"This error happens when Python sees a ",[24,25,26],"strong",{},"module"," where it expected something it can ",[24,29,30],{},"call"," with parentheses.",[20,33,34,35,38,39,42,43,46,47,50],{},"Beginners often run into this after writing code like ",[15,36,37],{},"math(16)"," or ",[15,40,41],{},"json(text)",". The problem is that ",[15,44,45],{},"math"," and ",[15,48,49],{},"json"," are modules. They contain functions and classes, but the module itself is not a function.",[52,53,55],"h2",{"id":54},"quick-fix","Quick fix",[57,58,63],"pre",{"className":59,"code":60,"language":61,"meta":62,"style":62},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","import math\n\n# Wrong:\n# result = math(16)\n\n# Right:\nresult = math.sqrt(16)\nprint(result)\n","python","",[15,64,65,78,85,92,98,103,109,140],{"__ignoreMap":62},[66,67,70,74],"span",{"class":68,"line":69},"line",1,[66,71,73],{"class":72},"sVHd0","import",[66,75,77],{"class":76},"su5hD"," math\n",[66,79,81],{"class":68,"line":80},2,[66,82,84],{"emptyLinePlaceholder":83},true,"\n",[66,86,88],{"class":68,"line":87},3,[66,89,91],{"class":90},"sutJx","# Wrong:\n",[66,93,95],{"class":68,"line":94},4,[66,96,97],{"class":90},"# result = math(16)\n",[66,99,101],{"class":68,"line":100},5,[66,102,84],{"emptyLinePlaceholder":83},[66,104,106],{"class":68,"line":105},6,[66,107,108],{"class":90},"# Right:\n",[66,110,112,115,119,122,126,130,133,137],{"class":68,"line":111},7,[66,113,114],{"class":76},"result ",[66,116,118],{"class":117},"smGrS","=",[66,120,121],{"class":76}," math",[66,123,125],{"class":124},"sP7_E",".",[66,127,129],{"class":128},"slqww","sqrt",[66,131,132],{"class":124},"(",[66,134,136],{"class":135},"srdBf","16",[66,138,139],{"class":124},")\n",[66,141,143,147,149,152],{"class":68,"line":142},8,[66,144,146],{"class":145},"sptTA","print",[66,148,132],{"class":124},[66,150,151],{"class":128},"result",[66,153,139],{"class":124},[20,155,156],{},"Output:",[57,158,160],{"className":59,"code":159,"language":61,"meta":62,"style":62},"4.0\n",[15,161,162],{"__ignoreMap":62},[66,163,164],{"class":68,"line":69},[66,165,159],{"class":135},[20,167,168,169,172],{},"A module is a container for functions, classes, and variables. Call something ",[24,170,171],{},"inside"," the module, not the module itself.",[52,174,176],{"id":175},"what-this-error-means","What this error means",[20,178,179,180,183],{},"Python found a ",[24,181,182],{},"module object"," where it expected something callable.",[20,185,186,187,190],{},"A ",[24,188,189],{},"callable"," is something you can use with parentheses, such as:",[192,193,194,198,201],"ul",{},[195,196,197],"li",{},"a function",[195,199,200],{},"a class",[195,202,203],{},"some special objects that behave like functions",[20,205,206,207,125],{},"A module is different. It groups related code together, but you do not call a module with ",[15,208,209],{},"()",[20,211,212],{},"For example:",[57,214,216],{"className":59,"code":215,"language":61,"meta":62,"style":62},"import math\n\nprint(type(math))\n",[15,217,218,224,228],{"__ignoreMap":62},[66,219,220,222],{"class":68,"line":69},[66,221,73],{"class":72},[66,223,77],{"class":76},[66,225,226],{"class":68,"line":80},[66,227,84],{"emptyLinePlaceholder":83},[66,229,230,232,234,238,240,242],{"class":68,"line":87},[66,231,146],{"class":145},[66,233,132],{"class":124},[66,235,237],{"class":236},"sZMiF","type",[66,239,132],{"class":124},[66,241,45],{"class":128},[66,243,244],{"class":124},"))\n",[20,246,156],{},[57,248,250],{"className":59,"code":249,"language":61,"meta":62,"style":62},"\u003Cclass 'module'>\n",[15,251,252],{"__ignoreMap":62},[66,253,254,257,261,265,268,271],{"class":68,"line":69},[66,255,256],{"class":117},"\u003C",[66,258,260],{"class":259},"sbsja","class",[66,262,264],{"class":263},"sjJ54"," '",[66,266,26],{"class":267},"s_sjI",[66,269,270],{"class":263},"'",[66,272,273],{"class":117},">\n",[20,275,276,277,125],{},"If you want to inspect this more, see ",[278,279,281,282,285],"a",{"href":280},"\u002Freference\u002Fpython-type-function-explained\u002F","Python ",[15,283,284],{},"type()"," explained",[52,287,289],{"id":288},"common-example-that-causes-the-error","Common example that causes the error",[20,291,292],{},"A very common mistake looks like this:",[57,294,296],{"className":59,"code":295,"language":61,"meta":62,"style":62},"import math\n\nprint(math(10))\n",[15,297,298,304,308],{"__ignoreMap":62},[66,299,300,302],{"class":68,"line":69},[66,301,73],{"class":72},[66,303,77],{"class":76},[66,305,306],{"class":68,"line":80},[66,307,84],{"emptyLinePlaceholder":83},[66,309,310,312,314,316,318,321],{"class":68,"line":87},[66,311,146],{"class":145},[66,313,132],{"class":124},[66,315,45],{"class":128},[66,317,132],{"class":124},[66,319,320],{"class":135},"10",[66,322,244],{"class":124},[20,324,325],{},"This raises:",[57,327,329],{"className":59,"code":328,"language":61,"meta":62,"style":62},"TypeError: 'module' object is not callable\n",[15,330,331],{"__ignoreMap":62},[66,332,333,336,339,341,343,345,348,351,354],{"class":68,"line":69},[66,334,335],{"class":236},"TypeError",[66,337,338],{"class":124},":",[66,340,264],{"class":263},[66,342,26],{"class":267},[66,344,270],{"class":263},[66,346,347],{"class":236}," object",[66,349,350],{"class":117}," is",[66,352,353],{"class":117}," not",[66,355,356],{"class":145}," callable\n",[20,358,359],{},"Why?",[192,361,362,371,376],{},[195,363,364,367,368,370],{},[15,365,366],{},"import math"," imports the ",[15,369,45],{}," module",[195,372,373,375],{},[15,374,45],{}," is now the name of that module",[195,377,378,381],{},[15,379,380],{},"math(10)"," tries to call the module like a function",[20,383,384,385,387],{},"But ",[15,386,45],{}," is not a function. It is a module.",[52,389,391],{"id":390},"fix-1-call-the-function-inside-the-module","Fix 1: Call the function inside the module",[20,393,394,395,398],{},"Use ",[24,396,397],{},"dot notation"," to access a function inside the module.",[400,401,403,404],"h3",{"id":402},"example-with-math","Example with ",[15,405,45],{},[57,407,409],{"className":59,"code":408,"language":61,"meta":62,"style":62},"import math\n\nprint(math.sqrt(10))\n",[15,410,411,417,421],{"__ignoreMap":62},[66,412,413,415],{"class":68,"line":69},[66,414,73],{"class":72},[66,416,77],{"class":76},[66,418,419],{"class":68,"line":80},[66,420,84],{"emptyLinePlaceholder":83},[66,422,423,425,427,429,431,433,435,437],{"class":68,"line":87},[66,424,146],{"class":145},[66,426,132],{"class":124},[66,428,45],{"class":128},[66,430,125],{"class":124},[66,432,129],{"class":128},[66,434,132],{"class":124},[66,436,320],{"class":135},[66,438,244],{"class":124},[20,440,156],{},[57,442,444],{"className":59,"code":443,"language":61,"meta":62,"style":62},"3.1622776601683795\n",[15,445,446],{"__ignoreMap":62},[66,447,448],{"class":68,"line":69},[66,449,443],{"class":135},[400,451,403,453],{"id":452},"example-with-random",[15,454,455],{},"random",[57,457,459],{"className":59,"code":458,"language":61,"meta":62,"style":62},"import random\n\nprint(random.randint(1, 5))\n",[15,460,461,468,472],{"__ignoreMap":62},[66,462,463,465],{"class":68,"line":69},[66,464,73],{"class":72},[66,466,467],{"class":76}," random\n",[66,469,470],{"class":68,"line":80},[66,471,84],{"emptyLinePlaceholder":83},[66,473,474,476,478,480,482,485,487,490,493,496],{"class":68,"line":87},[66,475,146],{"class":145},[66,477,132],{"class":124},[66,479,455],{"class":128},[66,481,125],{"class":124},[66,483,484],{"class":128},"randint",[66,486,132],{"class":124},[66,488,489],{"class":135},"1",[66,491,492],{"class":124},",",[66,494,495],{"class":135}," 5",[66,497,244],{"class":124},[20,499,500],{},"Example output:",[57,502,504],{"className":59,"code":503,"language":61,"meta":62,"style":62},"3\n",[15,505,506],{"__ignoreMap":62},[66,507,508],{"class":68,"line":69},[66,509,503],{"class":135},[400,511,403,513],{"id":512},"example-with-json",[15,514,49],{},[57,516,518],{"className":59,"code":517,"language":61,"meta":62,"style":62},"import json\n\ntext = '{\"name\": \"Ana\"}'\ndata = json.loads(text)\nprint(data)\n",[15,519,520,527,531,546,568],{"__ignoreMap":62},[66,521,522,524],{"class":68,"line":69},[66,523,73],{"class":72},[66,525,526],{"class":76}," json\n",[66,528,529],{"class":68,"line":80},[66,530,84],{"emptyLinePlaceholder":83},[66,532,533,536,538,540,543],{"class":68,"line":87},[66,534,535],{"class":76},"text ",[66,537,118],{"class":117},[66,539,264],{"class":263},[66,541,542],{"class":267},"{\"name\": \"Ana\"}",[66,544,545],{"class":263},"'\n",[66,547,548,551,553,556,558,561,563,566],{"class":68,"line":94},[66,549,550],{"class":76},"data ",[66,552,118],{"class":117},[66,554,555],{"class":76}," json",[66,557,125],{"class":124},[66,559,560],{"class":128},"loads",[66,562,132],{"class":124},[66,564,565],{"class":128},"text",[66,567,139],{"class":124},[66,569,570,572,574,577],{"class":68,"line":100},[66,571,146],{"class":145},[66,573,132],{"class":124},[66,575,576],{"class":128},"data",[66,578,139],{"class":124},[20,580,156],{},[57,582,584],{"className":59,"code":583,"language":61,"meta":62,"style":62},"{'name': 'Ana'}\n",[15,585,586],{"__ignoreMap":62},[66,587,588,591,593,596,598,600,602,605,607],{"class":68,"line":69},[66,589,590],{"class":124},"{",[66,592,270],{"class":263},[66,594,595],{"class":267},"name",[66,597,270],{"class":263},[66,599,338],{"class":124},[66,601,264],{"class":263},[66,603,604],{"class":267},"Ana",[66,606,270],{"class":263},[66,608,609],{"class":124},"}\n",[20,611,612,613,619,620,38,624,125],{},"If you are not sure what a module contains, you can inspect it with ",[278,614,616],{"href":615},"\u002Freference\u002Fpython-dir-function-explained\u002F",[15,617,618],{},"dir()"," or read a module overview such as the ",[278,621,623],{"href":622},"\u002Fstandard-library\u002Fpython-math-module-overview\u002F","Python math module overview",[278,625,627],{"href":626},"\u002Fstandard-library\u002Fpython-json-module-overview\u002F","Python json module overview",[52,629,631],{"id":630},"fix-2-import-the-function-directly","Fix 2: Import the function directly",[20,633,634],{},"If you only need one function, you can import that function directly.",[57,636,638],{"className":59,"code":637,"language":61,"meta":62,"style":62},"from math import sqrt\n\nprint(sqrt(10))\n",[15,639,640,653,657],{"__ignoreMap":62},[66,641,642,645,648,650],{"class":68,"line":69},[66,643,644],{"class":72},"from",[66,646,647],{"class":76}," math ",[66,649,73],{"class":72},[66,651,652],{"class":76}," sqrt\n",[66,654,655],{"class":68,"line":80},[66,656,84],{"emptyLinePlaceholder":83},[66,658,659,661,663,665,667,669],{"class":68,"line":87},[66,660,146],{"class":145},[66,662,132],{"class":124},[66,664,129],{"class":128},[66,666,132],{"class":124},[66,668,320],{"class":135},[66,670,244],{"class":124},[20,672,156],{},[57,674,675],{"className":59,"code":443,"language":61,"meta":62,"style":62},[15,676,677],{"__ignoreMap":62},[66,678,679],{"class":68,"line":69},[66,680,443],{"class":135},[20,682,683,684,686,687,690],{},"This works because ",[15,685,129],{}," is a function, so ",[15,688,689],{},"sqrt(10)"," is valid.",[20,692,693],{},"Compare these two styles:",[57,695,697],{"className":59,"code":696,"language":61,"meta":62,"style":62},"import math\nprint(math.sqrt(10))\n",[15,698,699,705],{"__ignoreMap":62},[66,700,701,703],{"class":68,"line":69},[66,702,73],{"class":72},[66,704,77],{"class":76},[66,706,707,709,711,713,715,717,719,721],{"class":68,"line":80},[66,708,146],{"class":145},[66,710,132],{"class":124},[66,712,45],{"class":128},[66,714,125],{"class":124},[66,716,129],{"class":128},[66,718,132],{"class":124},[66,720,320],{"class":135},[66,722,244],{"class":124},[57,724,726],{"className":59,"code":725,"language":61,"meta":62,"style":62},"from math import sqrt\nprint(sqrt(10))\n",[15,727,728,738],{"__ignoreMap":62},[66,729,730,732,734,736],{"class":68,"line":69},[66,731,644],{"class":72},[66,733,647],{"class":76},[66,735,73],{"class":72},[66,737,652],{"class":76},[66,739,740,742,744,746,748,750],{"class":68,"line":80},[66,741,146],{"class":145},[66,743,132],{"class":124},[66,745,129],{"class":128},[66,747,132],{"class":124},[66,749,320],{"class":135},[66,751,244],{"class":124},[20,753,754,755,758],{},"Both are correct. The important part is that you call the ",[24,756,757],{},"function",", not the module.",[20,760,761,762,125],{},"If imports still feel confusing, read ",[278,763,765],{"href":764},"\u002Flearn\u002Fhow-import-works-in-python\u002F","how imports work in Python",[52,767,769],{"id":768},"fix-3-check-for-name-collisions","Fix 3: Check for name collisions",[20,771,772],{},"Sometimes the problem is not your function call. The problem is that a name points to a module when you did not expect it to.",[400,774,776],{"id":775},"case-1-reusing-a-name","Case 1: Reusing a name",[57,778,780],{"className":59,"code":779,"language":61,"meta":62,"style":62},"import math\n\n# math is the module here\nprint(type(math))\n",[15,781,782,788,792,797],{"__ignoreMap":62},[66,783,784,786],{"class":68,"line":69},[66,785,73],{"class":72},[66,787,77],{"class":76},[66,789,790],{"class":68,"line":80},[66,791,84],{"emptyLinePlaceholder":83},[66,793,794],{"class":68,"line":87},[66,795,796],{"class":90},"# math is the module here\n",[66,798,799,801,803,805,807,809],{"class":68,"line":94},[66,800,146],{"class":145},[66,802,132],{"class":124},[66,804,237],{"class":236},[66,806,132],{"class":124},[66,808,45],{"class":128},[66,810,244],{"class":124},[20,812,813,814,816],{},"If you thought ",[15,815,45],{}," was a function, the import statement shows otherwise.",[400,818,820],{"id":819},"case-2-your-file-name-shadows-a-real-module","Case 2: Your file name shadows a real module",[20,822,823],{},"This is a very common beginner problem.",[20,825,826,827,830,831,833],{},"For example, if your file is named ",[15,828,829],{},"random.py",", this can interfere with importing Python's real ",[15,832,455],{}," module.",[20,835,836],{},"A file structure like this can cause trouble:",[57,838,840],{"className":59,"code":839,"language":61,"meta":62,"style":62},"random.py\nmain.py\n",[15,841,842,852],{"__ignoreMap":62},[66,843,844,846,848],{"class":68,"line":69},[66,845,455],{"class":76},[66,847,125],{"class":124},[66,849,851],{"class":850},"skxfh","py\n",[66,853,854,857,859],{"class":68,"line":80},[66,855,856],{"class":76},"main",[66,858,125],{"class":124},[66,860,851],{"class":850},[20,862,863,864,338],{},"And in ",[15,865,866],{},"main.py",[57,868,870],{"className":59,"code":869,"language":61,"meta":62,"style":62},"import random\n\nprint(random(1, 5))\n",[15,871,872,878,882],{"__ignoreMap":62},[66,873,874,876],{"class":68,"line":69},[66,875,73],{"class":72},[66,877,467],{"class":76},[66,879,880],{"class":68,"line":80},[66,881,84],{"emptyLinePlaceholder":83},[66,883,884,886,888,890,892,894,896,898],{"class":68,"line":87},[66,885,146],{"class":145},[66,887,132],{"class":124},[66,889,455],{"class":128},[66,891,132],{"class":124},[66,893,489],{"class":135},[66,895,492],{"class":124},[66,897,495],{"class":135},[66,899,244],{"class":124},[20,901,902],{},"This is wrong for two reasons:",[192,904,905,910],{},[195,906,907,909],{},[15,908,455],{}," is being called like a function",[195,911,912],{},"your local file name may be shadowing the real module",[20,914,915],{},"A better fix is:",[192,917,918,924,931],{},[195,919,920,921],{},"rename your file to something else, like ",[15,922,923],{},"my_random_tools.py",[195,925,926,927,930],{},"delete any ",[15,928,929],{},"__pycache__"," folder if needed",[195,932,933],{},"import the real module again",[20,935,936],{},"Then use the correct function:",[57,938,939],{"className":59,"code":458,"language":61,"meta":62,"style":62},[15,940,941,947,951],{"__ignoreMap":62},[66,942,943,945],{"class":68,"line":69},[66,944,73],{"class":72},[66,946,467],{"class":76},[66,948,949],{"class":68,"line":80},[66,950,84],{"emptyLinePlaceholder":83},[66,952,953,955,957,959,961,963,965,967,969,971],{"class":68,"line":87},[66,954,146],{"class":145},[66,956,132],{"class":124},[66,958,455],{"class":128},[66,960,125],{"class":124},[66,962,484],{"class":128},[66,964,132],{"class":124},[66,966,489],{"class":135},[66,968,492],{"class":124},[66,970,495],{"class":135},[66,972,244],{"class":124},[20,974,975,976,125],{},"If Python cannot import the module you expect, you may also want to read ",[278,977,979],{"href":978},"\u002Ferrors\u002Fimporterror-no-module-named-x-fix\u002F","ImportError: No module named X",[52,981,983],{"id":982},"common-modules-beginners-misuse-this-way","Common modules beginners misuse this way",[20,985,986],{},"These modules are often called by mistake:",[192,988,989,993,997,1001,1006],{},[195,990,991],{},[15,992,45],{},[195,994,995],{},[15,996,455],{},[195,998,999],{},[15,1000,49],{},[195,1002,1003],{},[15,1004,1005],{},"datetime",[195,1007,1008],{},[15,1009,1010],{},"os",[20,1012,1013],{},"Examples of wrong code:",[57,1015,1017],{"className":59,"code":1016,"language":61,"meta":62,"style":62},"import math\nmath(5)\n",[15,1018,1019,1025],{"__ignoreMap":62},[66,1020,1021,1023],{"class":68,"line":69},[66,1022,73],{"class":72},[66,1024,77],{"class":76},[66,1026,1027,1029,1031,1034],{"class":68,"line":80},[66,1028,45],{"class":128},[66,1030,132],{"class":124},[66,1032,1033],{"class":135},"5",[66,1035,139],{"class":124},[57,1037,1039],{"className":59,"code":1038,"language":61,"meta":62,"style":62},"import random\nrandom(1, 10)\n",[15,1040,1041,1047],{"__ignoreMap":62},[66,1042,1043,1045],{"class":68,"line":69},[66,1044,73],{"class":72},[66,1046,467],{"class":76},[66,1048,1049,1051,1053,1055,1057,1060],{"class":68,"line":80},[66,1050,455],{"class":128},[66,1052,132],{"class":124},[66,1054,489],{"class":135},[66,1056,492],{"class":124},[66,1058,1059],{"class":135}," 10",[66,1061,139],{"class":124},[57,1063,1065],{"className":59,"code":1064,"language":61,"meta":62,"style":62},"import json\njson('{\"a\": 1}')\n",[15,1066,1067,1073],{"__ignoreMap":62},[66,1068,1069,1071],{"class":68,"line":69},[66,1070,73],{"class":72},[66,1072,526],{"class":76},[66,1074,1075,1077,1079,1081,1084,1086],{"class":68,"line":80},[66,1076,49],{"class":128},[66,1078,132],{"class":124},[66,1080,270],{"class":263},[66,1082,1083],{"class":267},"{\"a\": 1}",[66,1085,270],{"class":263},[66,1087,139],{"class":124},[20,1089,1090],{},"Correct versions:",[57,1092,1094],{"className":59,"code":1093,"language":61,"meta":62,"style":62},"import math\nprint(math.sqrt(5))\n",[15,1095,1096,1102],{"__ignoreMap":62},[66,1097,1098,1100],{"class":68,"line":69},[66,1099,73],{"class":72},[66,1101,77],{"class":76},[66,1103,1104,1106,1108,1110,1112,1114,1116,1118],{"class":68,"line":80},[66,1105,146],{"class":145},[66,1107,132],{"class":124},[66,1109,45],{"class":128},[66,1111,125],{"class":124},[66,1113,129],{"class":128},[66,1115,132],{"class":124},[66,1117,1033],{"class":135},[66,1119,244],{"class":124},[57,1121,1123],{"className":59,"code":1122,"language":61,"meta":62,"style":62},"import random\nprint(random.randint(1, 10))\n",[15,1124,1125,1131],{"__ignoreMap":62},[66,1126,1127,1129],{"class":68,"line":69},[66,1128,73],{"class":72},[66,1130,467],{"class":76},[66,1132,1133,1135,1137,1139,1141,1143,1145,1147,1149,1151],{"class":68,"line":80},[66,1134,146],{"class":145},[66,1136,132],{"class":124},[66,1138,455],{"class":128},[66,1140,125],{"class":124},[66,1142,484],{"class":128},[66,1144,132],{"class":124},[66,1146,489],{"class":135},[66,1148,492],{"class":124},[66,1150,1059],{"class":135},[66,1152,244],{"class":124},[57,1154,1156],{"className":59,"code":1155,"language":61,"meta":62,"style":62},"import json\nprint(json.loads('{\"a\": 1}'))\n",[15,1157,1158,1164],{"__ignoreMap":62},[66,1159,1160,1162],{"class":68,"line":69},[66,1161,73],{"class":72},[66,1163,526],{"class":76},[66,1165,1166,1168,1170,1172,1174,1176,1178,1180,1182,1184],{"class":68,"line":80},[66,1167,146],{"class":145},[66,1169,132],{"class":124},[66,1171,49],{"class":128},[66,1173,125],{"class":124},[66,1175,560],{"class":128},[66,1177,132],{"class":124},[66,1179,270],{"class":263},[66,1181,1083],{"class":267},[66,1183,270],{"class":263},[66,1185,244],{"class":124},[20,1187,1188,1189,125],{},"For more examples, see the ",[278,1190,1192],{"href":1191},"\u002Fstandard-library\u002Fpython-random-module-overview\u002F","Python random module overview",[52,1194,1196],{"id":1195},"how-to-debug-it-step-by-step","How to debug it step by step",[20,1198,1199],{},"When you see this error, use this checklist.",[400,1201,1203],{"id":1202},"_1-find-the-name-directly-before-the-parentheses","1. Find the name directly before the parentheses",[20,1205,1206],{},"In code like this:",[57,1208,1210],{"className":59,"code":1209,"language":61,"meta":62,"style":62},"math(10)\n",[15,1211,1212],{"__ignoreMap":62},[66,1213,1214,1216,1218,1220],{"class":68,"line":69},[66,1215,45],{"class":128},[66,1217,132],{"class":124},[66,1219,320],{"class":135},[66,1221,139],{"class":124},[20,1223,1224,1225,125],{},"The name before the parentheses is ",[15,1226,45],{},[20,1228,1229],{},"That is the object Python is trying to call.",[400,1231,1233],{"id":1232},"_2-check-how-that-name-was-imported","2. Check how that name was imported",[20,1235,1236],{},"Look for lines like:",[57,1238,1240],{"className":59,"code":1239,"language":61,"meta":62,"style":62},"import math\n",[15,1241,1242],{"__ignoreMap":62},[66,1243,1244,1246],{"class":68,"line":69},[66,1245,73],{"class":72},[66,1247,77],{"class":76},[20,1249,1250],{},"or:",[57,1252,1254],{"className":59,"code":1253,"language":61,"meta":62,"style":62},"from math import sqrt\n",[15,1255,1256],{"__ignoreMap":62},[66,1257,1258,1260,1262,1264],{"class":68,"line":69},[66,1259,644],{"class":72},[66,1261,647],{"class":76},[66,1263,73],{"class":72},[66,1265,652],{"class":76},[20,1267,1268],{},"These two imports create different names.",[192,1270,1271,1278],{},[195,1272,1273,1275,1276],{},[15,1274,366],{}," gives you the module name ",[15,1277,45],{},[195,1279,1280,1283,1284],{},[15,1281,1282],{},"from math import sqrt"," gives you the function name ",[15,1285,129],{},[400,1287,1289],{"id":1288},"_3-print-the-type","3. Print the type",[57,1291,1293],{"className":59,"code":1292,"language":61,"meta":62,"style":62},"import math\n\nprint(type(math))\nprint(math)\n",[15,1294,1295,1301,1305,1319],{"__ignoreMap":62},[66,1296,1297,1299],{"class":68,"line":69},[66,1298,73],{"class":72},[66,1300,77],{"class":76},[66,1302,1303],{"class":68,"line":80},[66,1304,84],{"emptyLinePlaceholder":83},[66,1306,1307,1309,1311,1313,1315,1317],{"class":68,"line":87},[66,1308,146],{"class":145},[66,1310,132],{"class":124},[66,1312,237],{"class":236},[66,1314,132],{"class":124},[66,1316,45],{"class":128},[66,1318,244],{"class":124},[66,1320,1321,1323,1325,1327],{"class":68,"line":94},[66,1322,146],{"class":145},[66,1324,132],{"class":124},[66,1326,45],{"class":128},[66,1328,139],{"class":124},[20,1330,1331],{},"Possible output:",[57,1333,1335],{"className":59,"code":1334,"language":61,"meta":62,"style":62},"\u003Cclass 'module'>\n\u003Cmodule 'math' from '...'>\n",[15,1336,1337,1351],{"__ignoreMap":62},[66,1338,1339,1341,1343,1345,1347,1349],{"class":68,"line":69},[66,1340,256],{"class":117},[66,1342,260],{"class":259},[66,1344,264],{"class":263},[66,1346,26],{"class":267},[66,1348,270],{"class":263},[66,1350,273],{"class":117},[66,1352,1353,1355,1358,1360,1362,1364,1367,1369,1372,1374],{"class":68,"line":80},[66,1354,256],{"class":117},[66,1356,1357],{"class":76},"module ",[66,1359,270],{"class":263},[66,1361,45],{"class":267},[66,1363,270],{"class":263},[66,1365,1366],{"class":72}," from",[66,1368,264],{"class":263},[66,1370,1371],{"class":267},"...",[66,1373,270],{"class":263},[66,1375,273],{"class":117},[20,1377,1378,1379,1381],{},"If it says ",[15,1380,26],{},", then you know why calling it fails.",[400,1383,1385],{"id":1384},"_4-see-what-the-module-contains","4. See what the module contains",[57,1387,1389],{"className":59,"code":1388,"language":61,"meta":62,"style":62},"import math\n\nprint(dir(math))\n",[15,1390,1391,1397,1401],{"__ignoreMap":62},[66,1392,1393,1395],{"class":68,"line":69},[66,1394,73],{"class":72},[66,1396,77],{"class":76},[66,1398,1399],{"class":68,"line":80},[66,1400,84],{"emptyLinePlaceholder":83},[66,1402,1403,1405,1407,1410,1412,1414],{"class":68,"line":87},[66,1404,146],{"class":145},[66,1406,132],{"class":124},[66,1408,1409],{"class":145},"dir",[66,1411,132],{"class":124},[66,1413,45],{"class":128},[66,1415,244],{"class":124},[20,1417,1418,1419,1421,1422,1425,1426,125],{},"This shows the names inside the module, such as ",[15,1420,129],{},", ",[15,1423,1424],{},"ceil",", and ",[15,1427,1428],{},"floor",[400,1430,1432],{"id":1431},"_5-call-a-function-inside-the-module-instead","5. Call a function inside the module instead",[57,1434,1436],{"className":59,"code":1435,"language":61,"meta":62,"style":62},"import math\n\nprint(math.sqrt(16))\n",[15,1437,1438,1444,1448],{"__ignoreMap":62},[66,1439,1440,1442],{"class":68,"line":69},[66,1441,73],{"class":72},[66,1443,77],{"class":76},[66,1445,1446],{"class":68,"line":80},[66,1447,84],{"emptyLinePlaceholder":83},[66,1449,1450,1452,1454,1456,1458,1460,1462,1464],{"class":68,"line":87},[66,1451,146],{"class":145},[66,1453,132],{"class":124},[66,1455,45],{"class":128},[66,1457,125],{"class":124},[66,1459,129],{"class":128},[66,1461,132],{"class":124},[66,1463,136],{"class":135},[66,1465,244],{"class":124},[400,1467,1469],{"id":1468},"_6-check-for-local-files-that-shadow-real-modules","6. Check for local files that shadow real modules",[20,1471,1472,1473,1421,1476,1421,1479,1481,1482,1485],{},"If you have files named ",[15,1474,1475],{},"math.py",[15,1477,1478],{},"json.py",[15,1480,829],{},", or ",[15,1483,1484],{},"datetime.py",", rename them.",[20,1487,1488],{},"You can also inspect Python's import path:",[57,1490,1492],{"className":59,"code":1491,"language":61,"meta":62,"style":62},"import sys\nprint(sys.path)\n",[15,1493,1494,1501],{"__ignoreMap":62},[66,1495,1496,1498],{"class":68,"line":69},[66,1497,73],{"class":72},[66,1499,1500],{"class":76}," sys\n",[66,1502,1503,1505,1507,1510,1512,1515],{"class":68,"line":80},[66,1504,146],{"class":145},[66,1506,132],{"class":124},[66,1508,1509],{"class":128},"sys",[66,1511,125],{"class":124},[66,1513,1514],{"class":850},"path",[66,1516,139],{"class":124},[20,1518,1519],{},"That helps when Python is importing from a place you did not expect.",[52,1521,1523],{"id":1522},"how-this-differs-from-similar-errors","How this differs from similar errors",[20,1525,1526,1527,125],{},"This error is specific: it means ",[24,1528,1529],{},"the module itself was called",[400,1531,1533,1534],{"id":1532},"different-from-typeerror-list-object-is-not-callable","Different from ",[15,1535,1536],{},"TypeError: 'list' object is not callable",[20,1538,1539],{},"That error means you called a list like a function.",[20,1541,1542],{},"Example:",[57,1544,1546],{"className":59,"code":1545,"language":61,"meta":62,"style":62},"numbers = [1, 2, 3]\nnumbers(0)\n",[15,1547,1548,1573],{"__ignoreMap":62},[66,1549,1550,1553,1555,1558,1560,1562,1565,1567,1570],{"class":68,"line":69},[66,1551,1552],{"class":76},"numbers ",[66,1554,118],{"class":117},[66,1556,1557],{"class":124}," [",[66,1559,489],{"class":135},[66,1561,492],{"class":124},[66,1563,1564],{"class":135}," 2",[66,1566,492],{"class":124},[66,1568,1569],{"class":135}," 3",[66,1571,1572],{"class":124},"]\n",[66,1574,1575,1578,1580,1583],{"class":68,"line":80},[66,1576,1577],{"class":128},"numbers",[66,1579,132],{"class":124},[66,1581,1582],{"class":135},"0",[66,1584,139],{"class":124},[20,1586,1587,1588,125],{},"That is a different problem. See ",[278,1589,1536],{"href":1590},"\u002Ferrors\u002Ftypeerror-list-object-is-not-callable-fix\u002F",[400,1592,1533,1594],{"id":1593},"different-from-attributeerror-module-has-no-attribute",[15,1595,1596],{},"AttributeError: module has no attribute",[20,1598,1599],{},"That error means the module exists, but the name after the dot is wrong.",[20,1601,1542],{},[57,1603,1605],{"className":59,"code":1604,"language":61,"meta":62,"style":62},"import math\nprint(math.square_root(4))\n",[15,1606,1607,1613],{"__ignoreMap":62},[66,1608,1609,1611],{"class":68,"line":69},[66,1610,73],{"class":72},[66,1612,77],{"class":76},[66,1614,1615,1617,1619,1621,1623,1626,1628,1631],{"class":68,"line":80},[66,1616,146],{"class":145},[66,1618,132],{"class":124},[66,1620,45],{"class":128},[66,1622,125],{"class":124},[66,1624,1625],{"class":128},"square_root",[66,1627,132],{"class":124},[66,1629,1630],{"class":135},"4",[66,1632,244],{"class":124},[20,1634,1635,1636,1638],{},"Here, Python found the module, but ",[15,1637,1625],{}," is not a valid attribute.",[20,1640,1641,1642,125],{},"That is different from calling the module itself. See ",[278,1643,1596],{"href":1644},"\u002Ferrors\u002Fattributeerror-module-has-no-attribute-fix\u002F",[52,1646,1648],{"id":1647},"common-causes","Common causes",[20,1650,1651],{},"This error usually comes from one of these mistakes:",[192,1653,1654,1664,1667,1670,1673],{},[195,1655,1656,1657,1660,1661],{},"Using ",[15,1658,1659],{},"import module_name"," and then calling ",[15,1662,1663],{},"module_name()",[195,1665,1666],{},"Forgetting the function name after the module name",[195,1668,1669],{},"Confusing a module with a class or function",[195,1671,1672],{},"Importing the module when you meant to import a function",[195,1674,1675],{},"Naming your own file the same as a module and creating import confusion",[52,1677,1679],{"id":1678},"useful-debugging-commands","Useful debugging commands",[20,1681,1682],{},"These commands can help you confirm what a name refers to:",[57,1684,1686],{"className":59,"code":1685,"language":61,"meta":62,"style":62},"print(type(math))\nprint(math)\nprint(dir(math))\nimport sys; print(sys.path)\n",[15,1687,1688,1702,1712,1726],{"__ignoreMap":62},[66,1689,1690,1692,1694,1696,1698,1700],{"class":68,"line":69},[66,1691,146],{"class":145},[66,1693,132],{"class":124},[66,1695,237],{"class":236},[66,1697,132],{"class":124},[66,1699,45],{"class":128},[66,1701,244],{"class":124},[66,1703,1704,1706,1708,1710],{"class":68,"line":80},[66,1705,146],{"class":145},[66,1707,132],{"class":124},[66,1709,45],{"class":128},[66,1711,139],{"class":124},[66,1713,1714,1716,1718,1720,1722,1724],{"class":68,"line":87},[66,1715,146],{"class":145},[66,1717,132],{"class":124},[66,1719,1409],{"class":145},[66,1721,132],{"class":124},[66,1723,45],{"class":128},[66,1725,244],{"class":124},[66,1727,1728,1730,1733,1735,1737,1739,1741,1743],{"class":68,"line":94},[66,1729,73],{"class":72},[66,1731,1732],{"class":76}," sys; ",[66,1734,146],{"class":145},[66,1736,132],{"class":124},[66,1738,1509],{"class":128},[66,1740,125],{"class":124},[66,1742,1514],{"class":850},[66,1744,139],{"class":124},[20,1746,1747],{},"Use them when you are not sure whether something is:",[192,1749,1750,1753,1755,1757],{},[195,1751,1752],{},"a module",[195,1754,197],{},[195,1756,200],{},[195,1758,1759],{},"a local file being imported by mistake",[52,1761,1763],{"id":1762},"faq","FAQ",[400,1765,1767],{"id":1766},"why-does-python-say-a-module-is-not-callable","Why does Python say a module is not callable?",[20,1769,1770],{},"Because you used parentheses on a module name, but only functions, classes, and some other objects can be called.",[400,1772,1774],{"id":1773},"how-do-i-know-if-something-is-a-module","How do I know if something is a module?",[20,1776,394,1777,38,1780,1783],{},[15,1778,1779],{},"type(name)",[15,1781,1782],{},"print(name)",". A module often appears like this:",[57,1785,1787],{"className":59,"code":1786,"language":61,"meta":62,"style":62},"\u003Cmodule 'math' ...>\n",[15,1788,1789],{"__ignoreMap":62},[66,1790,1791,1793,1795,1797,1799,1801,1805],{"class":68,"line":69},[66,1792,256],{"class":117},[66,1794,1357],{"class":76},[66,1796,270],{"class":263},[66,1798,45],{"class":267},[66,1800,270],{"class":263},[66,1802,1804],{"class":1803},"s_hVV"," ...",[66,1806,273],{"class":117},[400,1808,1810],{"id":1809},"can-i-ever-call-a-module-directly","Can I ever call a module directly?",[20,1812,1813],{},"No. You call functions or classes inside the module, not the module itself.",[400,1815,1817],{"id":1816},"what-if-i-imported-the-wrong-thing","What if I imported the wrong thing?",[20,1819,1820],{},"Change the import statement.",[20,1822,1823,1824,1827],{},"For example, if you want to call ",[15,1825,1826],{},"sqrt()"," directly, use:",[57,1829,1831],{"className":59,"code":1830,"language":61,"meta":62,"style":62},"from math import sqrt\n\nprint(sqrt(9))\n",[15,1832,1833,1843,1847],{"__ignoreMap":62},[66,1834,1835,1837,1839,1841],{"class":68,"line":69},[66,1836,644],{"class":72},[66,1838,647],{"class":76},[66,1840,73],{"class":72},[66,1842,652],{"class":76},[66,1844,1845],{"class":68,"line":80},[66,1846,84],{"emptyLinePlaceholder":83},[66,1848,1849,1851,1853,1855,1857,1860],{"class":68,"line":87},[66,1850,146],{"class":145},[66,1852,132],{"class":124},[66,1854,129],{"class":128},[66,1856,132],{"class":124},[66,1858,1859],{"class":135},"9",[66,1861,244],{"class":124},[400,1863,1865],{"id":1864},"why-does-this-happen-with-my-own-file-names","Why does this happen with my own file names?",[20,1867,1868],{},"If your file has the same name as a real module, Python may import your file instead of the standard library module. That can lead to confusing behavior and hard-to-read errors.",[52,1870,1872],{"id":1871},"see-also","See also",[192,1874,1875,1880,1886,1892,1896,1900,1904],{},[195,1876,1877],{},[278,1878,1879],{"href":764},"How imports work in Python",[195,1881,1882],{},[278,1883,281,1884,285],{"href":280},[15,1885,284],{},[195,1887,1888],{},[278,1889,281,1890,285],{"href":615},[15,1891,618],{},[195,1893,1894],{},[278,1895,623],{"href":622},[195,1897,1898],{},[278,1899,1192],{"href":1191},[195,1901,1902],{},[278,1903,627],{"href":626},[195,1905,1906],{},[278,1907,1596],{"href":1644},[20,1909,1910],{},"If you want to avoid this error in future code, start by checking the object's type, fixing the import, and learning how Python resolves module names during import.",[1912,1913,1914],"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 .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 pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}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 .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}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 .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":62,"searchDepth":80,"depth":80,"links":1916},[1917,1918,1919,1920,1928,1929,1933,1934,1942,1948,1949,1950,1957],{"id":54,"depth":80,"text":55},{"id":175,"depth":80,"text":176},{"id":288,"depth":80,"text":289},{"id":390,"depth":80,"text":391,"children":1921},[1922,1924,1926],{"id":402,"depth":87,"text":1923},"Example with math",{"id":452,"depth":87,"text":1925},"Example with random",{"id":512,"depth":87,"text":1927},"Example with json",{"id":630,"depth":80,"text":631},{"id":768,"depth":80,"text":769,"children":1930},[1931,1932],{"id":775,"depth":87,"text":776},{"id":819,"depth":87,"text":820},{"id":982,"depth":80,"text":983},{"id":1195,"depth":80,"text":1196,"children":1935},[1936,1937,1938,1939,1940,1941],{"id":1202,"depth":87,"text":1203},{"id":1232,"depth":87,"text":1233},{"id":1288,"depth":87,"text":1289},{"id":1384,"depth":87,"text":1385},{"id":1431,"depth":87,"text":1432},{"id":1468,"depth":87,"text":1469},{"id":1522,"depth":80,"text":1523,"children":1943},[1944,1946],{"id":1532,"depth":87,"text":1945},"Different from TypeError: 'list' object is not callable",{"id":1593,"depth":87,"text":1947},"Different from AttributeError: module has no attribute",{"id":1647,"depth":80,"text":1648},{"id":1678,"depth":80,"text":1679},{"id":1762,"depth":80,"text":1763,"children":1951},[1952,1953,1954,1955,1956],{"id":1766,"depth":87,"text":1767},{"id":1773,"depth":87,"text":1774},{"id":1809,"depth":87,"text":1810},{"id":1816,"depth":87,"text":1817},{"id":1864,"depth":87,"text":1865},{"id":1871,"depth":80,"text":1872},"Master typeerror module object is not callable fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Ftypeerror-module-object-is-not-callable-fix",{"title":5,"description":1958},"errors\u002Ftypeerror-module-object-is-not-callable-fix","RggJn92uR9X_pzv9-RlwWRe9CV8Wc1e0lKVwer1MqU4",1777585512247]