[{"data":1,"prerenderedAt":1789},["ShallowReactive",2],{"doc-\u002Flearn\u002Fhow-to-run-python-code-command-line-and-ides":3},{"id":4,"title":5,"body":6,"description":1782,"extension":1783,"meta":1784,"navigation":118,"path":1785,"seo":1786,"stem":1787,"__hash__":1788},"content\u002Flearn\u002Fhow-to-run-python-code-command-line-and-ides.md","How to Run Python Code (Command Line and IDEs)",{"type":7,"value":8,"toc":1724},"minimark",[9,13,22,25,46,49,166,187,192,195,210,218,222,225,228,244,247,258,261,272,275,283,294,315,319,325,328,339,344,347,355,358,367,374,377,383,387,393,412,415,421,424,442,444,450,454,457,479,487,491,496,502,506,513,532,536,541,545,548,560,562,573,576,587,589,595,598,605,608,615,664,667,679,682,688,705,709,715,718,725,731,743,745,757,761,764,773,776,785,788,792,794,803,809,818,821,824,834,837,843,846,857,860,863,870,873,884,888,906,910,913,932,935,954,961,964,1019,1026,1029,1033,1036,1040,1043,1057,1059,1065,1069,1072,1086,1091,1126,1128,1134,1137,1141,1144,1148,1151,1159,1162,1180,1182,1187,1191,1196,1214,1216,1226,1228,1233,1237,1242,1284,1286,1298,1301,1307,1311,1314,1320,1323,1340,1343,1366,1373,1376,1382,1399,1403,1412,1415,1424,1427,1433,1443,1447,1450,1454,1457,1460,1475,1482,1486,1489,1548,1551,1565,1569,1578,1581,1595,1599,1602,1605,1616,1620,1623,1632,1639,1642,1645,1649,1657,1661,1664,1672,1676,1720],[10,11,5],"h1",{"id":12},"how-to-run-python-code-command-line-and-ides",[14,15,16,17,21],"p",{},"If you are new to Python, one of the first things to learn is ",[18,19,20],"strong",{},"how to actually run your code",".",[14,23,24],{},"This page shows you how to:",[26,27,28,32,40,43],"ul",{},[29,30,31],"li",{},"Run Python in the terminal for quick tests",[29,33,34,35,39],{},"Run a saved ",[36,37,38],"code",{},".py"," file from the command line",[29,41,42],{},"Run Python code in common IDEs and editors",[29,44,45],{},"Understand when to use interactive mode and when to use script files",[14,47,48],{},"If you just want the fastest possible test, try this first:",[50,51,56],"pre",{"className":52,"code":53,"language":54,"meta":55,"style":55},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","python --version\npython\nprint(\"Hello, world!\")\nexit()\n\n# Save this as hello.py\nprint(\"Hello from a file\")\n\n# Run the file\npython hello.py\n","python","",[36,57,58,74,80,104,113,120,127,143,148,154],{"__ignoreMap":55},[59,60,63,67,71],"span",{"class":61,"line":62},"line",1,[59,64,66],{"class":65},"su5hD","python ",[59,68,70],{"class":69},"srjyR","--",[59,72,73],{"class":65},"version\n",[59,75,77],{"class":61,"line":76},2,[59,78,79],{"class":65},"python\n",[59,81,83,87,91,95,99,101],{"class":61,"line":82},3,[59,84,86],{"class":85},"sptTA","print",[59,88,90],{"class":89},"sP7_E","(",[59,92,94],{"class":93},"sjJ54","\"",[59,96,98],{"class":97},"s_sjI","Hello, world!",[59,100,94],{"class":93},[59,102,103],{"class":89},")\n",[59,105,107,110],{"class":61,"line":106},4,[59,108,109],{"class":85},"exit",[59,111,112],{"class":89},"()\n",[59,114,116],{"class":61,"line":115},5,[59,117,119],{"emptyLinePlaceholder":118},true,"\n",[59,121,123],{"class":61,"line":122},6,[59,124,126],{"class":125},"sutJx","# Save this as hello.py\n",[59,128,130,132,134,136,139,141],{"class":61,"line":129},7,[59,131,86],{"class":85},[59,133,90],{"class":89},[59,135,94],{"class":93},[59,137,138],{"class":97},"Hello from a file",[59,140,94],{"class":93},[59,142,103],{"class":89},[59,144,146],{"class":61,"line":145},8,[59,147,119],{"emptyLinePlaceholder":118},[59,149,151],{"class":61,"line":150},9,[59,152,153],{"class":125},"# Run the file\n",[59,155,157,160,162],{"class":61,"line":156},10,[59,158,159],{"class":65},"python hello",[59,161,21],{"class":89},[59,163,165],{"class":164},"skxfh","py\n",[167,168,169],"blockquote",{},[14,170,171,172,174,175,178,179,182,183,186],{},"If ",[36,173,54],{}," does not work, try ",[36,176,177],{},"python3"," instead. On some systems the Python launcher ",[36,180,181],{},"py"," also works, such as ",[36,184,185],{},"py hello.py"," on Windows.",[188,189,191],"h2",{"id":190},"what-this-page-helps-you-do","What this page helps you do",[14,193,194],{},"After reading this page, you should be able to:",[26,196,197,200,204,207],{},[29,198,199],{},"Run Python interactively in a terminal",[29,201,34,202,39],{},[36,203,38],{},[29,205,206],{},"Run Python code in an IDE or code editor",[29,208,209],{},"Understand the difference between interactive mode and script files",[14,211,212,213,21],{},"If you have not installed Python yet, see ",[214,215,217],"a",{"href":216},"\u002Flearn\u002Fhow-to-install-python-on-windows-macos-and-linux","how to install Python on Windows, macOS, and Linux",[188,219,221],{"id":220},"before-you-run-python-code","Before you run Python code",[14,223,224],{},"First, make sure Python is installed.",[14,226,227],{},"Open a terminal or command prompt and try one of these commands:",[50,229,233],{"className":230,"code":231,"language":232,"meta":55,"style":55},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","python --version\n","bash",[36,234,235],{"__ignoreMap":55},[59,236,237,240],{"class":61,"line":62},[59,238,54],{"class":239},"sbgvK",[59,241,243],{"class":242},"stzsN"," --version\n",[14,245,246],{},"If that does not work, try:",[50,248,250],{"className":230,"code":249,"language":232,"meta":55,"style":55},"python3 --version\n",[36,251,252],{"__ignoreMap":55},[59,253,254,256],{"class":61,"line":62},[59,255,177],{"class":239},[59,257,243],{"class":242},[14,259,260],{},"On Windows, this may also work:",[50,262,264],{"className":230,"code":263,"language":232,"meta":55,"style":55},"py --version\n",[36,265,266],{"__ignoreMap":55},[59,267,268,270],{"class":61,"line":62},[59,269,181],{"class":239},[59,271,243],{"class":242},[14,273,274],{},"You should see a version number, such as:",[50,276,281],{"className":277,"code":279,"language":280,"meta":55},[278],"language-text","Python 3.12.2\n","text",[36,282,279],{"__ignoreMap":55},[14,284,285,286,289,290,293],{},"If you get a message like ",[18,287,288],{},"command not found"," or ",[18,291,292],{},"python is not recognized",", one of these is probably true:",[26,295,296,299,305],{},[29,297,298],{},"Python is not installed",[29,300,301,302],{},"Python is installed but not added to your system ",[36,303,304],{},"PATH",[29,306,307,308,289,310,312,313],{},"You need to use ",[36,309,177],{},[36,311,181],{}," instead of ",[36,314,54],{},[188,316,318],{"id":317},"run-python-in-interactive-mode","Run Python in interactive mode",[14,320,321,322,21],{},"Interactive mode lets you type Python code ",[18,323,324],{},"one line at a time",[14,326,327],{},"This is useful for:",[26,329,330,333,336],{},[29,331,332],{},"Quick tests",[29,334,335],{},"Trying small examples",[29,337,338],{},"Checking how a function works",[340,341,343],"h3",{"id":342},"start-interactive-mode","Start interactive mode",[14,345,346],{},"In your terminal, type:",[50,348,349],{"className":230,"code":79,"language":232,"meta":55,"style":55},[36,350,351],{"__ignoreMap":55},[59,352,353],{"class":61,"line":62},[59,354,79],{"class":239},[14,356,357],{},"Or:",[50,359,361],{"className":230,"code":360,"language":232,"meta":55,"style":55},"python3\n",[36,362,363],{"__ignoreMap":55},[59,364,365],{"class":61,"line":62},[59,366,360],{"class":239},[14,368,369,370,373],{},"If it works, you will see the ",[36,371,372],{},">>>"," prompt. That means Python is ready.",[14,375,376],{},"Example:",[50,378,381],{"className":379,"code":380,"language":280,"meta":55},[278],">>> \n",[36,382,380],{"__ignoreMap":55},[340,384,386],{"id":385},"try-a-simple-example","Try a simple example",[14,388,389,390,392],{},"Type this at the ",[36,391,372],{}," prompt:",[50,394,396],{"className":52,"code":395,"language":54,"meta":55,"style":55},"print(\"Hello, world!\")\n",[36,397,398],{"__ignoreMap":55},[59,399,400,402,404,406,408,410],{"class":61,"line":62},[59,401,86],{"class":85},[59,403,90],{"class":89},[59,405,94],{"class":93},[59,407,98],{"class":97},[59,409,94],{"class":93},[59,411,103],{"class":89},[14,413,414],{},"Expected output:",[50,416,419],{"className":417,"code":418,"language":280,"meta":55},[278],"Hello, world!\n",[36,420,418],{"__ignoreMap":55},[14,422,423],{},"You can also try simple math:",[50,425,427],{"className":52,"code":426,"language":54,"meta":55,"style":55},"2 + 3\n",[36,428,429],{"__ignoreMap":55},[59,430,431,435,439],{"class":61,"line":62},[59,432,434],{"class":433},"srdBf","2",[59,436,438],{"class":437},"smGrS"," +",[59,440,441],{"class":433}," 3\n",[14,443,414],{},[50,445,448],{"className":446,"code":447,"language":280,"meta":55},[278],"5\n",[36,449,447],{"__ignoreMap":55},[340,451,453],{"id":452},"exit-interactive-mode","Exit interactive mode",[14,455,456],{},"To leave interactive mode:",[26,458,459,466,473],{},[29,460,461,462,465],{},"Type ",[36,463,464],{},"exit()"," and press Enter",[29,467,468,469,472],{},"On Windows, press ",[36,470,471],{},"Ctrl+Z",", then Enter",[29,474,475,476],{},"On macOS\u002FLinux, press ",[36,477,478],{},"Ctrl+D",[14,480,481,482,486],{},"If you are learning basic Python syntax, ",[214,483,485],{"href":484},"\u002Flearn\u002Fyour-first-python-program-hello-world-explained\u002F","your first Python program: Hello World explained"," is a good next step.",[188,488,490],{"id":489},"run-a-python-file-from-the-command-line","Run a Python file from the command line",[14,492,493,494,21],{},"For real programs, you usually save your code in a file ending with ",[36,495,38],{},[14,497,498,499,21],{},"This is called a ",[18,500,501],{},"script file",[340,503,505],{"id":504},"step-1-create-a-python-file","Step 1: Create a Python file",[14,507,508,509,512],{},"Create a file named ",[36,510,511],{},"hello.py"," and put this code in it:",[50,514,516],{"className":52,"code":515,"language":54,"meta":55,"style":55},"print(\"Hello from a file\")\n",[36,517,518],{"__ignoreMap":55},[59,519,520,522,524,526,528,530],{"class":61,"line":62},[59,521,86],{"class":85},[59,523,90],{"class":89},[59,525,94],{"class":93},[59,527,138],{"class":97},[59,529,94],{"class":93},[59,531,103],{"class":89},[340,533,535],{"id":534},"step-2-open-the-terminal-in-the-same-folder","Step 2: Open the terminal in the same folder",[14,537,538,539,21],{},"Your terminal needs to be in the folder that contains ",[36,540,511],{},[340,542,544],{"id":543},"step-3-run-the-file","Step 3: Run the file",[14,546,547],{},"Use one of these commands:",[50,549,551],{"className":230,"code":550,"language":232,"meta":55,"style":55},"python hello.py\n",[36,552,553],{"__ignoreMap":55},[59,554,555,557],{"class":61,"line":62},[59,556,54],{"class":239},[59,558,559],{"class":97}," hello.py\n",[14,561,357],{},[50,563,565],{"className":230,"code":564,"language":232,"meta":55,"style":55},"python3 hello.py\n",[36,566,567],{"__ignoreMap":55},[59,568,569,571],{"class":61,"line":62},[59,570,177],{"class":239},[59,572,559],{"class":97},[14,574,575],{},"Or on Windows:",[50,577,579],{"className":230,"code":578,"language":232,"meta":55,"style":55},"py hello.py\n",[36,580,581],{"__ignoreMap":55},[59,582,583,585],{"class":61,"line":62},[59,584,181],{"class":239},[59,586,559],{"class":97},[14,588,414],{},[50,590,593],{"className":591,"code":592,"language":280,"meta":55},[278],"Hello from a file\n",[36,594,592],{"__ignoreMap":55},[14,596,597],{},"This is the normal way to run saved Python programs.",[340,599,601,602],{"id":600},"example-with-input","Example with ",[36,603,604],{},"input()",[14,606,607],{},"Scripts can also pause and wait for user input.",[14,609,610,611,614],{},"Save this as ",[36,612,613],{},"name.py",":",[50,616,618],{"className":52,"code":617,"language":54,"meta":55,"style":55},"name = input(\"What is your name? \")\nprint(\"Hello,\", name)\n",[36,619,620,642],{"__ignoreMap":55},[59,621,622,625,628,631,633,635,638,640],{"class":61,"line":62},[59,623,624],{"class":65},"name ",[59,626,627],{"class":437},"=",[59,629,630],{"class":85}," input",[59,632,90],{"class":89},[59,634,94],{"class":93},[59,636,637],{"class":97},"What is your name? ",[59,639,94],{"class":93},[59,641,103],{"class":89},[59,643,644,646,648,650,653,655,658,662],{"class":61,"line":76},[59,645,86],{"class":85},[59,647,90],{"class":89},[59,649,94],{"class":93},[59,651,652],{"class":97},"Hello,",[59,654,94],{"class":93},[59,656,657],{"class":89},",",[59,659,661],{"class":660},"slqww"," name",[59,663,103],{"class":89},[14,665,666],{},"Run it:",[50,668,670],{"className":230,"code":669,"language":232,"meta":55,"style":55},"python name.py\n",[36,671,672],{"__ignoreMap":55},[59,673,674,676],{"class":61,"line":62},[59,675,54],{"class":239},[59,677,678],{"class":97}," name.py\n",[14,680,681],{},"Example session:",[50,683,686],{"className":684,"code":685,"language":280,"meta":55},[278],"What is your name? Sam\nHello, Sam\n",[36,687,685],{"__ignoreMap":55},[14,689,690,691,698,699,21],{},"If you want to understand this line better, see ",[214,692,694,695,697],{"href":693},"\u002Freference\u002Fpython-input-function-explained\u002F","Python ",[36,696,604],{}," explained"," and ",[214,700,694,702,697],{"href":701},"\u002Freference\u002Fpython-print-function-explained\u002F",[36,703,704],{},"print()",[188,706,708],{"id":707},"how-to-open-the-correct-folder-in-the-terminal","How to open the correct folder in the terminal",[14,710,711,712,21],{},"A very common beginner problem is being in the ",[18,713,714],{},"wrong folder",[14,716,717],{},"If Python says it cannot open your file, check where your terminal is currently located.",[340,719,721,722],{"id":720},"move-to-a-folder-with-cd","Move to a folder with ",[36,723,724],{},"cd",[14,726,727,728,730],{},"Use ",[36,729,724],{}," to change folders:",[50,732,734],{"className":230,"code":733,"language":232,"meta":55,"style":55},"cd path\u002Fto\u002Ffolder\n",[36,735,736],{"__ignoreMap":55},[59,737,738,740],{"class":61,"line":62},[59,739,724],{"class":85},[59,741,742],{"class":97}," path\u002Fto\u002Ffolder\n",[14,744,376],{},[50,746,748],{"className":230,"code":747,"language":232,"meta":55,"style":55},"cd Desktop\u002Fpython-practice\n",[36,749,750],{"__ignoreMap":55},[59,751,752,754],{"class":61,"line":62},[59,753,724],{"class":85},[59,755,756],{"class":97}," Desktop\u002Fpython-practice\n",[340,758,760],{"id":759},"check-the-files-in-the-current-folder","Check the files in the current folder",[14,762,763],{},"On Windows:",[50,765,767],{"className":230,"code":766,"language":232,"meta":55,"style":55},"dir\n",[36,768,769],{"__ignoreMap":55},[59,770,771],{"class":61,"line":62},[59,772,766],{"class":239},[14,774,775],{},"On macOS\u002FLinux:",[50,777,779],{"className":230,"code":778,"language":232,"meta":55,"style":55},"ls\n",[36,780,781],{"__ignoreMap":55},[59,782,783],{"class":61,"line":62},[59,784,778],{"class":239},[14,786,787],{},"You should see your Python file listed.",[340,789,791],{"id":790},"check-your-current-location","Check your current location",[14,793,775],{},[50,795,797],{"className":230,"code":796,"language":232,"meta":55,"style":55},"pwd\n",[36,798,799],{"__ignoreMap":55},[59,800,801],{"class":61,"line":62},[59,802,796],{"class":85},[14,804,805,806,808],{},"On Windows, ",[36,807,724],{}," by itself often shows the current folder:",[50,810,812],{"className":230,"code":811,"language":232,"meta":55,"style":55},"cd\n",[36,813,814],{"__ignoreMap":55},[59,815,816],{"class":61,"line":62},[59,817,811],{"class":85},[14,819,820],{},"If your file is not in that folder, Python will not find it.",[14,822,823],{},"Example problem:",[50,825,826],{"className":230,"code":550,"language":232,"meta":55,"style":55},[36,827,828],{"__ignoreMap":55},[59,829,830,832],{"class":61,"line":62},[59,831,54],{"class":239},[59,833,559],{"class":97},[14,835,836],{},"Possible error:",[50,838,841],{"className":839,"code":840,"language":280,"meta":55},[278],"python: can't open file 'hello.py': [Errno 2] No such file or directory\n",[36,842,840],{"__ignoreMap":55},[14,844,845],{},"This usually means:",[26,847,848,851,854],{},[29,849,850],{},"You are in the wrong folder",[29,852,853],{},"The file name is wrong",[29,855,856],{},"The file was not saved yet",[188,858,206],{"id":859},"run-python-code-in-an-ide-or-code-editor",[14,861,862],{},"You do not have to use the terminal every time.",[14,864,865,866,869],{},"Most IDEs and code editors can run Python files with a ",[18,867,868],{},"Run"," button.",[14,871,872],{},"Common beginner tools include:",[26,874,875,878,881],{},[29,876,877],{},"IDLE",[29,879,880],{},"VS Code",[29,882,883],{},"PyCharm",[340,885,887],{"id":886},"the-basic-process-is-usually-the-same","The basic process is usually the same",[889,890,891,894,897,900],"ol",{},[29,892,893],{},"Open your Python file",[29,895,896],{},"Make sure the file is saved",[29,898,899],{},"Make sure the editor is using a valid Python interpreter",[29,901,902,903,905],{},"Click ",[18,904,868],{}," or use the editor's run shortcut",[340,907,909],{"id":908},"important-checks","Important checks",[14,911,912],{},"If the Run button does nothing, check these things:",[26,914,915,918,923,926,929],{},[29,916,917],{},"The file is saved",[29,919,920,921],{},"The file name ends with ",[36,922,38],{},[29,924,925],{},"Python is installed",[29,927,928],{},"The editor is using the correct Python interpreter",[29,930,931],{},"Your code does not contain a syntax error",[14,933,934],{},"For example, this code will fail because it is missing a closing parenthesis:",[50,936,938],{"className":52,"code":937,"language":54,"meta":55,"style":55},"print(\"Hello\"\n",[36,939,940],{"__ignoreMap":55},[59,941,942,944,946,948,951],{"class":61,"line":62},[59,943,86],{"class":85},[59,945,90],{"class":89},[59,947,94],{"class":93},[59,949,950],{"class":97},"Hello",[59,952,953],{"class":93},"\"\n",[14,955,956,957,21],{},"That causes a ",[214,958,960],{"href":959},"\u002Ferrors\u002Fsyntaxerror-invalid-syntax-fix\u002F","SyntaxError: invalid syntax",[14,962,963],{},"This code can also fail because of indentation problems:",[50,965,967],{"className":52,"code":966,"language":54,"meta":55,"style":55},"name = \"Sam\"\nif name == \"Sam\":\nprint(\"Hi\")\n",[36,968,969,983,1004],{"__ignoreMap":55},[59,970,971,973,975,978,981],{"class":61,"line":62},[59,972,624],{"class":65},[59,974,627],{"class":437},[59,976,977],{"class":93}," \"",[59,979,980],{"class":97},"Sam",[59,982,953],{"class":93},[59,984,985,989,992,995,997,999,1001],{"class":61,"line":76},[59,986,988],{"class":987},"sVHd0","if",[59,990,991],{"class":65}," name ",[59,993,994],{"class":437},"==",[59,996,977],{"class":93},[59,998,980],{"class":97},[59,1000,94],{"class":93},[59,1002,1003],{"class":89},":\n",[59,1005,1006,1008,1010,1012,1015,1017],{"class":61,"line":82},[59,1007,86],{"class":85},[59,1009,90],{"class":89},[59,1011,94],{"class":93},[59,1013,1014],{"class":97},"Hi",[59,1016,94],{"class":93},[59,1018,103],{"class":89},[14,1020,1021,1022,21],{},"That can cause an ",[214,1023,1025],{"href":1024},"\u002Ferrors\u002Findentationerror-expected-an-indented-block-fix\u002F","IndentationError: expected an indented block",[14,1027,1028],{},"If your code runs in the terminal but not in your editor, the editor may be using a different Python installation.",[188,1030,1032],{"id":1031},"interactive-mode-vs-running-a-script","Interactive mode vs running a script",[14,1034,1035],{},"These two ways of running Python are similar, but they are used for different purposes.",[340,1037,1039],{"id":1038},"interactive-mode","Interactive mode",[14,1041,1042],{},"Interactive mode:",[26,1044,1045,1048,1051,1054],{},[29,1046,1047],{},"Runs one command at a time",[29,1049,1050],{},"Shows results immediately",[29,1052,1053],{},"Is good for quick testing",[29,1055,1056],{},"Does not automatically save your code",[14,1058,376],{},[50,1060,1063],{"className":1061,"code":1062,"language":280,"meta":55},[278],">>> print(\"test\")\ntest\n>>> 10 * 2\n20\n",[36,1064,1062],{"__ignoreMap":55},[340,1066,1068],{"id":1067},"script-file","Script file",[14,1070,1071],{},"A script file:",[26,1073,1074,1077,1080,1083],{},[29,1075,1076],{},"Runs all saved code from top to bottom",[29,1078,1079],{},"Can be saved and used again later",[29,1081,1082],{},"Is better for larger programs",[29,1084,1085],{},"Is better for repeatable work",[14,1087,1088,1089,614],{},"Example ",[36,1090,511],{},[50,1092,1094],{"className":52,"code":1093,"language":54,"meta":55,"style":55},"print(\"Hello from a script\")\nprint(\"This runs from top to bottom\")\n",[36,1095,1096,1111],{"__ignoreMap":55},[59,1097,1098,1100,1102,1104,1107,1109],{"class":61,"line":62},[59,1099,86],{"class":85},[59,1101,90],{"class":89},[59,1103,94],{"class":93},[59,1105,1106],{"class":97},"Hello from a script",[59,1108,94],{"class":93},[59,1110,103],{"class":89},[59,1112,1113,1115,1117,1119,1122,1124],{"class":61,"line":76},[59,1114,86],{"class":85},[59,1116,90],{"class":89},[59,1118,94],{"class":93},[59,1120,1121],{"class":97},"This runs from top to bottom",[59,1123,94],{"class":93},[59,1125,103],{"class":89},[14,1127,414],{},[50,1129,1132],{"className":1130,"code":1131,"language":280,"meta":55},[278],"Hello from a script\nThis runs from top to bottom\n",[36,1133,1131],{"__ignoreMap":55},[14,1135,1136],{},"For beginners, interactive mode is great for experiments, but script files are better for real practice.",[188,1138,1140],{"id":1139},"expected-beginner-examples-to-include","Expected beginner examples to include",[14,1142,1143],{},"Here are three simple examples you can try right away.",[340,1145,1147],{"id":1146},"example-1-interactive-mode","Example 1: Interactive mode",[14,1149,1150],{},"Start Python:",[50,1152,1153],{"className":230,"code":79,"language":232,"meta":55,"style":55},[36,1154,1155],{"__ignoreMap":55},[59,1156,1157],{"class":61,"line":62},[59,1158,79],{"class":239},[14,1160,1161],{},"Then type:",[50,1163,1164],{"className":52,"code":395,"language":54,"meta":55,"style":55},[36,1165,1166],{"__ignoreMap":55},[59,1167,1168,1170,1172,1174,1176,1178],{"class":61,"line":62},[59,1169,86],{"class":85},[59,1171,90],{"class":89},[59,1173,94],{"class":93},[59,1175,98],{"class":97},[59,1177,94],{"class":93},[59,1179,103],{"class":89},[14,1181,414],{},[50,1183,1185],{"className":1184,"code":418,"language":280,"meta":55},[278],[36,1186,418],{"__ignoreMap":55},[340,1188,1190],{"id":1189},"example-2-run-a-saved-file","Example 2: Run a saved file",[14,1192,1193,1194,614],{},"Save this in ",[36,1195,511],{},[50,1197,1198],{"className":52,"code":515,"language":54,"meta":55,"style":55},[36,1199,1200],{"__ignoreMap":55},[59,1201,1202,1204,1206,1208,1210,1212],{"class":61,"line":62},[59,1203,86],{"class":85},[59,1205,90],{"class":89},[59,1207,94],{"class":93},[59,1209,138],{"class":97},[59,1211,94],{"class":93},[59,1213,103],{"class":89},[14,1215,666],{},[50,1217,1218],{"className":230,"code":550,"language":232,"meta":55,"style":55},[36,1219,1220],{"__ignoreMap":55},[59,1221,1222,1224],{"class":61,"line":62},[59,1223,54],{"class":239},[59,1225,559],{"class":97},[14,1227,414],{},[50,1229,1231],{"className":1230,"code":592,"language":280,"meta":55},[278],[36,1232,592],{"__ignoreMap":55},[340,1234,1236],{"id":1235},"example-3-script-with-user-input","Example 3: Script with user input",[14,1238,1193,1239,614],{},[36,1240,1241],{},"ask_name.py",[50,1243,1245],{"className":52,"code":1244,"language":54,"meta":55,"style":55},"name = input(\"What is your name? \")\nprint(\"Nice to meet you,\", name)\n",[36,1246,1247,1265],{"__ignoreMap":55},[59,1248,1249,1251,1253,1255,1257,1259,1261,1263],{"class":61,"line":62},[59,1250,624],{"class":65},[59,1252,627],{"class":437},[59,1254,630],{"class":85},[59,1256,90],{"class":89},[59,1258,94],{"class":93},[59,1260,637],{"class":97},[59,1262,94],{"class":93},[59,1264,103],{"class":89},[59,1266,1267,1269,1271,1273,1276,1278,1280,1282],{"class":61,"line":76},[59,1268,86],{"class":85},[59,1270,90],{"class":89},[59,1272,94],{"class":93},[59,1274,1275],{"class":97},"Nice to meet you,",[59,1277,94],{"class":93},[59,1279,657],{"class":89},[59,1281,661],{"class":660},[59,1283,103],{"class":89},[14,1285,666],{},[50,1287,1289],{"className":230,"code":1288,"language":232,"meta":55,"style":55},"python ask_name.py\n",[36,1290,1291],{"__ignoreMap":55},[59,1292,1293,1295],{"class":61,"line":62},[59,1294,54],{"class":239},[59,1296,1297],{"class":97}," ask_name.py\n",[14,1299,1300],{},"Example output:",[50,1302,1305],{"className":1303,"code":1304,"language":280,"meta":55},[278],"What is your name? Maya\nNice to meet you, Maya\n",[36,1306,1304],{"__ignoreMap":55},[188,1308,1310],{"id":1309},"common-problems-and-quick-checks","Common problems and quick checks",[14,1312,1313],{},"If Python is not running correctly, check these common problems first.",[340,1315,1317,1319],{"id":1316},"python-is-not-recognized-or-command-not-found",[36,1318,54],{}," is not recognized or command not found",[14,1321,1322],{},"Possible causes:",[26,1324,1325,1327,1332],{},[29,1326,298],{},[29,1328,1329,1330],{},"Python is not in ",[36,1331,304],{},[29,1333,1334,1335,289,1337,1339],{},"Your system uses ",[36,1336,177],{},[36,1338,181],{}," instead",[14,1341,1342],{},"Try:",[50,1344,1346],{"className":230,"code":1345,"language":232,"meta":55,"style":55},"python --version\npython3 --version\npy --version\n",[36,1347,1348,1354,1360],{"__ignoreMap":55},[59,1349,1350,1352],{"class":61,"line":62},[59,1351,54],{"class":239},[59,1353,243],{"class":242},[59,1355,1356,1358],{"class":61,"line":76},[59,1357,177],{"class":239},[59,1359,243],{"class":242},[59,1361,1362,1364],{"class":61,"line":82},[59,1363,181],{"class":239},[59,1365,243],{"class":242},[340,1367,1369,1370,1372],{"id":1368},"wrong-file-name-or-missing-py-extension","Wrong file name or missing ",[36,1371,38],{}," extension",[14,1374,1375],{},"Make sure the file name is exactly correct.",[14,1377,1378,1379,1381],{},"For example, ",[36,1380,511],{}," is not the same as:",[26,1383,1384,1389,1394],{},[29,1385,1386],{},[36,1387,1388],{},"Hello.py",[29,1390,1391],{},[36,1392,1393],{},"hello",[29,1395,1396],{},[36,1397,1398],{},"hello.py.txt",[340,1400,1402],{"id":1401},"running-from-the-wrong-folder","Running from the wrong folder",[14,1404,727,1405,289,1408,1411],{},[36,1406,1407],{},"ls",[36,1409,1410],{},"dir"," to make sure your file is in the current folder.",[14,1413,1414],{},"Then run it again.",[340,1416,1418,1419,1421,1422],{"id":1417},"using-python-when-the-system-needs-python3","Using ",[36,1420,54],{}," when the system needs ",[36,1423,177],{},[14,1425,1426],{},"Some systems separate Python 2 and Python 3 commands.",[14,1428,171,1429,1432],{},[36,1430,1431],{},"python hello.py"," fails, try:",[50,1434,1435],{"className":230,"code":564,"language":232,"meta":55,"style":55},[36,1436,1437],{"__ignoreMap":55},[59,1438,1439,1441],{"class":61,"line":62},[59,1440,177],{"class":239},[59,1442,559],{"class":97},[340,1444,1446],{"id":1445},"interpreter-not-selected-in-the-ide","Interpreter not selected in the IDE",[14,1448,1449],{},"If the terminal works but your IDE does not, check the selected interpreter in the editor settings.",[340,1451,1453],{"id":1452},"syntax-errors-stop-the-script","Syntax errors stop the script",[14,1455,1456],{},"If your script has invalid code, it will stop before finishing.",[14,1458,1459],{},"Common examples include:",[26,1461,1462,1467,1472],{},[29,1463,1464,1465],{},"Missing ",[36,1466,614],{},[29,1468,1464,1469],{},[36,1470,1471],{},")",[29,1473,1474],{},"Wrong indentation",[14,1476,1477,1478,21],{},"If you are stuck, see this ",[214,1479,1481],{"href":1480},"\u002Fhow-to\u002Fhow-to-debug-python-code-beginner-guide\u002F","beginner guide to debugging Python code",[188,1483,1485],{"id":1484},"beginner-debugging-commands","Beginner debugging commands",[14,1487,1488],{},"These commands help you quickly check what is wrong.",[50,1490,1492],{"className":230,"code":1491,"language":232,"meta":55,"style":55},"python --version\npython3 --version\npy --version\npwd\ncd path\u002Fto\u002Ffolder\nls\ndir\npython hello.py\npython3 hello.py\npy hello.py\n",[36,1493,1494,1500,1506,1512,1516,1522,1526,1530,1536,1542],{"__ignoreMap":55},[59,1495,1496,1498],{"class":61,"line":62},[59,1497,54],{"class":239},[59,1499,243],{"class":242},[59,1501,1502,1504],{"class":61,"line":76},[59,1503,177],{"class":239},[59,1505,243],{"class":242},[59,1507,1508,1510],{"class":61,"line":82},[59,1509,181],{"class":239},[59,1511,243],{"class":242},[59,1513,1514],{"class":61,"line":106},[59,1515,796],{"class":85},[59,1517,1518,1520],{"class":61,"line":115},[59,1519,724],{"class":85},[59,1521,742],{"class":97},[59,1523,1524],{"class":61,"line":122},[59,1525,778],{"class":239},[59,1527,1528],{"class":61,"line":129},[59,1529,766],{"class":239},[59,1531,1532,1534],{"class":61,"line":145},[59,1533,54],{"class":239},[59,1535,559],{"class":97},[59,1537,1538,1540],{"class":61,"line":150},[59,1539,177],{"class":239},[59,1541,559],{"class":97},[59,1543,1544,1546],{"class":61,"line":156},[59,1545,181],{"class":239},[59,1547,559],{"class":97},[14,1549,1550],{},"These commands can help you answer basic questions:",[26,1552,1553,1556,1559,1562],{},[29,1554,1555],{},"Is Python installed?",[29,1557,1558],{},"Which command works on this computer?",[29,1560,1561],{},"Am I in the correct folder?",[29,1563,1564],{},"Can Python find my file?",[188,1566,1568],{"id":1567},"faq","FAQ",[340,1570,1572,1573,289,1575,1577],{"id":1571},"should-i-use-python-or-python3","Should I use ",[36,1574,54],{},[36,1576,177],{},"?",[14,1579,1580],{},"Use the command that works on your system.",[26,1582,1583,1590],{},[29,1584,1585,1586,289,1588],{},"Many Windows systems use ",[36,1587,54],{},[36,1589,181],{},[29,1591,1592,1593],{},"Many macOS and Linux systems use ",[36,1594,177],{},[340,1596,1598],{"id":1597},"what-is-the-difference-between-the-terminal-and-an-ide","What is the difference between the terminal and an IDE?",[14,1600,1601],{},"The terminal runs commands directly.",[14,1603,1604],{},"An IDE gives you:",[26,1606,1607,1610,1613],{},[29,1608,1609],{},"A code editor",[29,1611,1612],{},"A Run button",[29,1614,1615],{},"Built-in tools for writing and debugging code",[340,1617,1619],{"id":1618},"why-does-python-say-it-cannot-open-my-file","Why does Python say it cannot open my file?",[14,1621,1622],{},"Usually one of these is the cause:",[26,1624,1625,1627,1629],{},[29,1626,850],{},[29,1628,853],{},[29,1630,1631],{},"The file was not saved",[340,1633,1635,1636,1638],{"id":1634},"what-does-mean-in-python","What does ",[36,1637,372],{}," mean in Python?",[14,1640,1641],{},"It is the prompt for Python interactive mode.",[14,1643,1644],{},"It means Python is ready for you to type code.",[340,1646,1648],{"id":1647},"can-i-run-python-without-saving-a-file","Can I run Python without saving a file?",[14,1650,1651,1652,289,1654,1656],{},"Yes. Use interactive mode by typing ",[36,1653,54],{},[36,1655,177],{}," in the terminal.",[340,1658,1660],{"id":1659},"why-does-my-code-work-in-the-terminal-but-not-in-my-ide","Why does my code work in the terminal but not in my IDE?",[14,1662,1663],{},"Usually:",[26,1665,1666,1669],{},[29,1667,1668],{},"The IDE is using a different Python interpreter",[29,1670,1671],{},"The file was not saved before running it",[188,1673,1675],{"id":1674},"see-also","See also",[26,1677,1678,1683,1688,1695,1701,1705,1709,1714],{},[29,1679,1680],{},[214,1681,1682],{"href":216},"How to install Python on Windows, macOS, and Linux",[29,1684,1685],{},[214,1686,1687],{"href":484},"Your first Python program: Hello World explained",[29,1689,1690],{},[214,1691,694,1692,1694],{"href":701},[36,1693,704],{}," function explained",[29,1696,1697],{},[214,1698,694,1699,1694],{"href":693},[36,1700,604],{},[29,1702,1703],{},[214,1704,960],{"href":959},[29,1706,1707],{},[214,1708,1025],{"href":1024},[29,1710,1711],{},[214,1712,1713],{"href":1480},"How to debug Python code: beginner guide",[29,1715,1716],{},[214,1717,1719],{"href":1718},"\u002Flearn\u002Fpython-modules-explained\u002F","Python modules explained",[1721,1722,1723],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .srjyR, html code.shiki .srjyR{--shiki-light:#90A4AE;--shiki-light-font-style:inherit;--shiki-default:#B31D28;--shiki-default-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic}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 .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 .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 .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--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 .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}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 .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}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}",{"title":55,"searchDepth":76,"depth":76,"links":1725},[1726,1727,1728,1733,1740,1746,1750,1754,1759,1770,1771,1781],{"id":190,"depth":76,"text":191},{"id":220,"depth":76,"text":221},{"id":317,"depth":76,"text":318,"children":1729},[1730,1731,1732],{"id":342,"depth":82,"text":343},{"id":385,"depth":82,"text":386},{"id":452,"depth":82,"text":453},{"id":489,"depth":76,"text":490,"children":1734},[1735,1736,1737,1738],{"id":504,"depth":82,"text":505},{"id":534,"depth":82,"text":535},{"id":543,"depth":82,"text":544},{"id":600,"depth":82,"text":1739},"Example with input()",{"id":707,"depth":76,"text":708,"children":1741},[1742,1744,1745],{"id":720,"depth":82,"text":1743},"Move to a folder with cd",{"id":759,"depth":82,"text":760},{"id":790,"depth":82,"text":791},{"id":859,"depth":76,"text":206,"children":1747},[1748,1749],{"id":886,"depth":82,"text":887},{"id":908,"depth":82,"text":909},{"id":1031,"depth":76,"text":1032,"children":1751},[1752,1753],{"id":1038,"depth":82,"text":1039},{"id":1067,"depth":82,"text":1068},{"id":1139,"depth":76,"text":1140,"children":1755},[1756,1757,1758],{"id":1146,"depth":82,"text":1147},{"id":1189,"depth":82,"text":1190},{"id":1235,"depth":82,"text":1236},{"id":1309,"depth":76,"text":1310,"children":1760},[1761,1763,1765,1766,1768,1769],{"id":1316,"depth":82,"text":1762},"python is not recognized or command not found",{"id":1368,"depth":82,"text":1764},"Wrong file name or missing .py extension",{"id":1401,"depth":82,"text":1402},{"id":1417,"depth":82,"text":1767},"Using python when the system needs python3",{"id":1445,"depth":82,"text":1446},{"id":1452,"depth":82,"text":1453},{"id":1484,"depth":76,"text":1485},{"id":1567,"depth":76,"text":1568,"children":1772},[1773,1775,1776,1777,1779,1780],{"id":1571,"depth":82,"text":1774},"Should I use python or python3?",{"id":1597,"depth":82,"text":1598},{"id":1618,"depth":82,"text":1619},{"id":1634,"depth":82,"text":1778},"What does >>> mean in Python?",{"id":1647,"depth":82,"text":1648},{"id":1659,"depth":82,"text":1660},{"id":1674,"depth":76,"text":1675},"Master how to run python code command line and ides in our comprehensive Python beginner guide.","md",{},"\u002Flearn\u002Fhow-to-run-python-code-command-line-and-ides",{"title":5,"description":1782},"learn\u002Fhow-to-run-python-code-command-line-and-ides","xNtiJ4fMvdKnUWiRmdCW9_q63hEf9kcc66mczXtaah4",1777585471424]