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