[{"data":1,"prerenderedAt":1584},["ShallowReactive",2],{"doc-\u002Fhow-to\u002Fhow-to-create-and-use-a-virtual-environment-in-python":3},{"id":4,"title":5,"body":6,"description":1577,"extension":1578,"meta":1579,"navigation":83,"path":1580,"seo":1581,"stem":1582,"__hash__":1583},"content\u002Fhow-to\u002Fhow-to-create-and-use-a-virtual-environment-in-python.md","How to Create and Use a Virtual Environment in Python",{"type":7,"value":8,"toc":1530},"minimark",[9,13,17,20,33,36,41,44,162,165,198,202,205,219,222,225,236,239,243,246,249,265,268,276,280,283,304,307,322,325,344,351,355,358,375,378,394,397,400,434,443,447,450,455,470,474,490,494,515,518,534,537,553,556,578,582,585,589,592,606,610,622,629,643,646,664,667,671,674,689,692,707,713,717,722,725,733,739,742,755,758,765,820,823,837,839,859,870,874,880,886,889,900,903,911,914,921,925,928,936,939,942,960,964,969,972,988,991,1002,1005,1009,1012,1016,1037,1044,1048,1067,1069,1080,1083,1129,1132,1173,1177,1183,1186,1189,1201,1207,1211,1214,1228,1231,1239,1243,1250,1253,1278,1284,1291,1294,1305,1308,1322,1326,1329,1352,1355,1406,1408,1420,1422,1434,1438,1442,1445,1454,1462,1470,1476,1483,1486,1490,1496,1500,1526],[10,11,5],"h1",{"id":12},"how-to-create-and-use-a-virtual-environment-in-python",[14,15,16],"p",{},"A virtual environment lets you create an isolated Python setup for one project.",[14,18,19],{},"This is useful when you want to:",[21,22,23,27,30],"ul",{},[24,25,26],"li",{},"install packages without affecting other projects",[24,28,29],{},"keep project dependencies separate",[24,31,32],{},"avoid version conflicts between libraries",[14,34,35],{},"On this page, you will learn how to create a virtual environment, activate it, install packages inside it, and leave it when you are done.",[37,38,40],"h2",{"id":39},"quick-answer","Quick answer",[14,42,43],{},"Use this when you want the fastest working setup:",[45,46,51],"pre",{"className":47,"code":48,"language":49,"meta":50,"style":50},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","python -m venv .venv\n\n# Windows\n.venv\\Scripts\\activate\n\n# macOS\u002FLinux\nsource .venv\u002Fbin\u002Factivate\n\npip install requests\n\ndeactivate\n","python","",[52,53,54,78,85,92,107,112,118,140,145,151,156],"code",{"__ignoreMap":50},[55,56,59,63,67,70,74],"span",{"class":57,"line":58},"line",1,[55,60,62],{"class":61},"su5hD","python ",[55,64,66],{"class":65},"smGrS","-",[55,68,69],{"class":61},"m venv ",[55,71,73],{"class":72},"sP7_E",".",[55,75,77],{"class":76},"skxfh","venv\n",[55,79,81],{"class":57,"line":80},2,[55,82,84],{"emptyLinePlaceholder":83},true,"\n",[55,86,88],{"class":57,"line":87},3,[55,89,91],{"class":90},"sutJx","# Windows\n",[55,93,95,97,100,103],{"class":57,"line":94},4,[55,96,73],{"class":72},[55,98,99],{"class":76},"venv",[55,101,102],{"class":72},"\\",[55,104,106],{"class":105},"srjyR","Scripts\\activate\n",[55,108,110],{"class":57,"line":109},5,[55,111,84],{"emptyLinePlaceholder":83},[55,113,115],{"class":57,"line":114},6,[55,116,117],{"class":90},"# macOS\u002FLinux\n",[55,119,121,124,126,128,131,135,137],{"class":57,"line":120},7,[55,122,123],{"class":61},"source ",[55,125,73],{"class":72},[55,127,99],{"class":76},[55,129,130],{"class":65},"\u002F",[55,132,134],{"class":133},"sptTA","bin",[55,136,130],{"class":65},[55,138,139],{"class":61},"activate\n",[55,141,143],{"class":57,"line":142},8,[55,144,84],{"emptyLinePlaceholder":83},[55,146,148],{"class":57,"line":147},9,[55,149,150],{"class":61},"pip install requests\n",[55,152,154],{"class":57,"line":153},10,[55,155,84],{"emptyLinePlaceholder":83},[55,157,159],{"class":57,"line":158},11,[55,160,161],{"class":61},"deactivate\n",[14,163,164],{},"What these commands do:",[21,166,167,176,182,192],{},[24,168,169,172,173],{},[52,170,171],{},"python -m venv .venv"," creates a new virtual environment in a folder named ",[52,174,175],{},".venv",[24,177,178,181],{},[52,179,180],{},"activate"," turns that environment on in your terminal",[24,183,184,187,188,191],{},[52,185,186],{},"pip install requests"," installs the ",[52,189,190],{},"requests"," package inside that environment",[24,193,194,197],{},[52,195,196],{},"deactivate"," turns the environment off",[37,199,201],{"id":200},"what-a-virtual-environment-is","What a virtual environment is",[14,203,204],{},"A virtual environment is a separate folder that contains:",[21,206,207,210,216],{},[24,208,209],{},"its own Python setup",[24,211,212,213],{},"its own ",[52,214,215],{},"pip",[24,217,218],{},"its own installed packages",[14,220,221],{},"This helps keep one project separate from another.",[14,223,224],{},"For example:",[21,226,227,230,233],{},[24,228,229],{},"Project A can use one version of a package",[24,231,232],{},"Project B can use a different version",[24,234,235],{},"neither project breaks the other",[14,237,238],{},"This is one of the safest habits to learn early in Python.",[37,240,242],{"id":241},"when-you-should-use-one","When you should use one",[14,244,245],{},"Use a virtual environment for almost every Python project.",[14,247,248],{},"It is especially helpful when:",[21,250,251,256,259,262],{},[24,252,253,254],{},"you plan to install third-party packages with ",[52,255,215],{},[24,257,258],{},"you are following a tutorial that needs extra libraries",[24,260,261],{},"you want to keep your system Python clean",[24,263,264],{},"different projects need different package versions",[14,266,267],{},"For a tiny one-file practice script, it may not always be necessary. But it is still a good habit.",[14,269,270,271,73],{},"If you are new to installing packages, see ",[272,273,275],"a",{"href":274},"\u002Fhow-to\u002Fhow-to-install-a-python-package-with-pip\u002F","how to install a Python package with pip",[37,277,279],{"id":278},"before-you-start","Before you start",[14,281,282],{},"Before creating the environment, make sure:",[21,284,285,288,293,296],{},[24,286,287],{},"Python is installed",[24,289,290,292],{},[52,291,49],{}," works in your terminal or command prompt",[24,294,295],{},"you opened the terminal in your project folder",[24,297,298,299,301,302],{},"you picked a clear environment name such as ",[52,300,175],{}," or ",[52,303,99],{},[14,305,306],{},"You can test Python with:",[45,308,310],{"className":47,"code":309,"language":49,"meta":50,"style":50},"python --version\n",[52,311,312],{"__ignoreMap":50},[55,313,314,316,319],{"class":57,"line":58},[55,315,62],{"class":61},[55,317,318],{"class":105},"--",[55,320,321],{"class":61},"version\n",[14,323,324],{},"Example output:",[45,326,328],{"className":47,"code":327,"language":49,"meta":50,"style":50},"Python 3.12.2\n",[52,329,330],{"__ignoreMap":50},[55,331,332,335,339,341],{"class":57,"line":58},[55,333,334],{"class":61},"Python ",[55,336,338],{"class":337},"srdBf","3.12",[55,340,73],{"class":72},[55,342,343],{"class":76},"2\n",[14,345,346,347,73],{},"If this does not work, you may need to ",[272,348,350],{"href":349},"\u002Flearn\u002Fhow-to-install-python-on-windows-macos-and-linux","install Python on Windows, macOS, and Linux",[37,352,354],{"id":353},"create-the-virtual-environment","Create the virtual environment",[14,356,357],{},"Run this command in your project folder:",[45,359,361],{"className":47,"code":360,"language":49,"meta":50,"style":50},"python -m venv .venv\n",[52,362,363],{"__ignoreMap":50},[55,364,365,367,369,371,373],{"class":57,"line":58},[55,366,62],{"class":61},[55,368,66],{"class":65},[55,370,69],{"class":61},[55,372,73],{"class":72},[55,374,77],{"class":76},[14,376,377],{},"What it does:",[21,379,380,383,389],{},[24,381,382],{},"runs Python",[24,384,385,386,388],{},"uses the built-in ",[52,387,99],{}," module",[24,390,391,392],{},"creates a new folder named ",[52,393,175],{},[14,395,396],{},"That folder stores the environment files and installed packages.",[14,398,399],{},"A simple project might look like this after creation:",[45,401,403],{"className":47,"code":402,"language":49,"meta":50,"style":50},"my_project\u002F\n├── .venv\u002F\n└── app.py\n",[52,404,405,413,424],{"__ignoreMap":50},[55,406,407,410],{"class":57,"line":58},[55,408,409],{"class":61},"my_project",[55,411,412],{"class":65},"\u002F\n",[55,414,415,418,420,422],{"class":57,"line":80},[55,416,417],{"class":61},"├── ",[55,419,73],{"class":72},[55,421,99],{"class":76},[55,423,412],{"class":65},[55,425,426,429,431],{"class":57,"line":87},[55,427,428],{"class":61},"└── app",[55,430,73],{"class":72},[55,432,433],{"class":76},"py\n",[14,435,436,437,439,440,442],{},"Do not edit files inside ",[52,438,175],{}," manually. Python and ",[52,441,215],{}," manage that folder for you.",[37,444,446],{"id":445},"activate-the-virtual-environment","Activate the virtual environment",[14,448,449],{},"After creating the environment, activate it.",[451,452,454],"h3",{"id":453},"windows-command-prompt","Windows Command Prompt",[45,456,458],{"className":47,"code":457,"language":49,"meta":50,"style":50},".venv\\Scripts\\activate\n",[52,459,460],{"__ignoreMap":50},[55,461,462,464,466,468],{"class":57,"line":58},[55,463,73],{"class":72},[55,465,99],{"class":76},[55,467,102],{"class":72},[55,469,106],{"class":105},[451,471,473],{"id":472},"windows-powershell","Windows PowerShell",[45,475,477],{"className":47,"code":476,"language":49,"meta":50,"style":50},".venv\\Scripts\\Activate.ps1\n",[52,478,479],{"__ignoreMap":50},[55,480,481,483,485,487],{"class":57,"line":58},[55,482,73],{"class":72},[55,484,99],{"class":76},[55,486,102],{"class":72},[55,488,489],{"class":105},"Scripts\\Activate.ps1\n",[451,491,493],{"id":492},"macos-and-linux","macOS and Linux",[45,495,497],{"className":47,"code":496,"language":49,"meta":50,"style":50},"source .venv\u002Fbin\u002Factivate\n",[52,498,499],{"__ignoreMap":50},[55,500,501,503,505,507,509,511,513],{"class":57,"line":58},[55,502,123],{"class":61},[55,504,73],{"class":72},[55,506,99],{"class":76},[55,508,130],{"class":65},[55,510,134],{"class":133},[55,512,130],{"class":65},[55,514,139],{"class":61},[14,516,517],{},"After activation:",[21,519,520,523,531],{},[24,521,522],{},"package installs go into this environment",[24,524,525,527,528,530],{},[52,526,49],{}," and ",[52,529,215],{}," usually point to the environment versions",[24,532,533],{},"your terminal often shows the environment name at the start",[14,535,536],{},"For example, your prompt may change from:",[45,538,540],{"className":47,"code":539,"language":49,"meta":50,"style":50},"C:\\projects\\my_project>\n",[52,541,542],{"__ignoreMap":50},[55,543,544,547,550],{"class":57,"line":58},[55,545,546],{"class":61},"C",[55,548,549],{"class":72},":\\",[55,551,552],{"class":105},"projects\\my_project>\n",[14,554,555],{},"to:",[45,557,559],{"className":47,"code":558,"language":49,"meta":50,"style":50},"(.venv) C:\\projects\\my_project>\n",[52,560,561],{"__ignoreMap":50},[55,562,563,566,568,571,574,576],{"class":57,"line":58},[55,564,565],{"class":72},"(.",[55,567,99],{"class":76},[55,569,570],{"class":72},")",[55,572,573],{"class":61}," C",[55,575,549],{"class":72},[55,577,552],{"class":105},[37,579,581],{"id":580},"check-that-it-is-active","Check that it is active",[14,583,584],{},"You can confirm that the environment is active in a few ways.",[451,586,588],{"id":587},"look-at-the-terminal-prompt","Look at the terminal prompt",[14,590,591],{},"Many terminals show the environment name, such as:",[45,593,595],{"className":47,"code":594,"language":49,"meta":50,"style":50},"(.venv)\n",[52,596,597],{"__ignoreMap":50},[55,598,599,601,603],{"class":57,"line":58},[55,600,565],{"class":72},[55,602,99],{"class":76},[55,604,605],{"class":72},")\n",[451,607,609],{"id":608},"check-the-python-version","Check the Python version",[45,611,612],{"className":47,"code":309,"language":49,"meta":50,"style":50},[52,613,614],{"__ignoreMap":50},[55,615,616,618,620],{"class":57,"line":58},[55,617,62],{"class":61},[55,619,318],{"class":105},[55,621,321],{"class":61},[451,623,625,626,628],{"id":624},"check-which-pip-is-being-used","Check which ",[52,627,215],{}," is being used",[45,630,632],{"className":47,"code":631,"language":49,"meta":50,"style":50},"pip --version\n",[52,633,634],{"__ignoreMap":50},[55,635,636,639,641],{"class":57,"line":58},[55,637,638],{"class":61},"pip ",[55,640,318],{"class":105},[55,642,321],{"class":61},[14,644,645],{},"You can also use:",[45,647,649],{"className":47,"code":648,"language":49,"meta":50,"style":50},"python -m pip --version\n",[52,650,651],{"__ignoreMap":50},[55,652,653,655,657,660,662],{"class":57,"line":58},[55,654,62],{"class":61},[55,656,66],{"class":65},[55,658,659],{"class":61},"m pip ",[55,661,318],{"class":105},[55,663,321],{"class":61},[14,665,666],{},"This is often more reliable because it uses the current Python interpreter directly.",[451,668,670],{"id":669},"check-the-python-path","Check the Python path",[14,672,673],{},"On Windows:",[45,675,677],{"className":47,"code":676,"language":49,"meta":50,"style":50},"where python\nwhere pip\n",[52,678,679,684],{"__ignoreMap":50},[55,680,681],{"class":57,"line":58},[55,682,683],{"class":61},"where python\n",[55,685,686],{"class":57,"line":80},[55,687,688],{"class":61},"where pip\n",[14,690,691],{},"On macOS\u002FLinux:",[45,693,695],{"className":47,"code":694,"language":49,"meta":50,"style":50},"which python\nwhich pip\n",[52,696,697,702],{"__ignoreMap":50},[55,698,699],{"class":57,"line":58},[55,700,701],{"class":61},"which python\n",[55,703,704],{"class":57,"line":80},[55,705,706],{"class":61},"which pip\n",[14,708,709,710,712],{},"If the environment is active, these commands should point to files inside the ",[52,711,175],{}," folder.",[37,714,716],{"id":715},"install-packages-inside-the-environment","Install packages inside the environment",[14,718,719,720,73],{},"Once the environment is active, you can install packages with ",[52,721,215],{},[14,723,724],{},"Example:",[45,726,727],{"className":47,"code":150,"language":49,"meta":50,"style":50},[52,728,729],{"__ignoreMap":50},[55,730,731],{"class":57,"line":58},[55,732,150],{"class":61},[14,734,735,736,738],{},"This installs ",[52,737,190],{}," only inside the current project environment.",[14,740,741],{},"You can check installed packages with:",[45,743,745],{"className":47,"code":744,"language":49,"meta":50,"style":50},"pip list\n",[52,746,747],{"__ignoreMap":50},[55,748,749,751],{"class":57,"line":58},[55,750,638],{"class":61},[55,752,754],{"class":753},"sZMiF","list\n",[14,756,757],{},"You can also test the package in Python code.",[14,759,760,761,764],{},"Create a file named ",[52,762,763],{},"app.py",":",[45,766,768],{"className":47,"code":767,"language":49,"meta":50,"style":50},"import requests\n\nprint(\"requests installed successfully\")\nprint(requests.__version__)\n",[52,769,770,779,783,803],{"__ignoreMap":50},[55,771,772,776],{"class":57,"line":58},[55,773,775],{"class":774},"sVHd0","import",[55,777,778],{"class":61}," requests\n",[55,780,781],{"class":57,"line":80},[55,782,84],{"emptyLinePlaceholder":83},[55,784,785,788,791,795,799,801],{"class":57,"line":87},[55,786,787],{"class":133},"print",[55,789,790],{"class":72},"(",[55,792,794],{"class":793},"sjJ54","\"",[55,796,798],{"class":797},"s_sjI","requests installed successfully",[55,800,794],{"class":793},[55,802,605],{"class":72},[55,804,805,807,809,812,814,818],{"class":57,"line":94},[55,806,787],{"class":133},[55,808,790],{"class":72},[55,810,190],{"class":811},"slqww",[55,813,73],{"class":72},[55,815,817],{"class":816},"s_hVV","__version__",[55,819,605],{"class":72},[14,821,822],{},"Run it with:",[45,824,826],{"className":47,"code":825,"language":49,"meta":50,"style":50},"python app.py\n",[52,827,828],{"__ignoreMap":50},[55,829,830,833,835],{"class":57,"line":58},[55,831,832],{"class":61},"python app",[55,834,73],{"class":72},[55,836,433],{"class":76},[14,838,324],{},[45,840,842],{"className":47,"code":841,"language":49,"meta":50,"style":50},"requests installed successfully\n2.32.3\n",[52,843,844,849],{"__ignoreMap":50},[55,845,846],{"class":57,"line":58},[55,847,848],{"class":61},"requests installed successfully\n",[55,850,851,854,856],{"class":57,"line":80},[55,852,853],{"class":337},"2.32",[55,855,73],{"class":72},[55,857,858],{"class":76},"3\n",[14,860,861,862,301,866,73],{},"If you are not sure how imports work, see ",[272,863,865],{"href":864},"\u002Flearn\u002Fhow-import-works-in-python","how imports work in Python",[272,867,869],{"href":868},"\u002Fhow-to\u002Fhow-to-import-a-module-in-python\u002F","how to import a module in Python",[37,871,873],{"id":872},"use-the-environment-in-your-editor-or-ide","Use the environment in your editor or IDE",[14,875,876,877,879],{},"Many editors detect a ",[52,878,175],{}," folder automatically.",[14,881,882,883,885],{},"If yours does not, choose the Python interpreter from the ",[52,884,175],{}," folder manually.",[14,887,888],{},"This matters because:",[21,890,891,894,897],{},[24,892,893],{},"Run and Debug should use the same interpreter as your terminal",[24,895,896],{},"installed packages must be available in both places",[24,898,899],{},"using the wrong interpreter can cause import errors",[14,901,902],{},"A common beginner problem is:",[21,904,905,908],{},[24,906,907],{},"the package works in the terminal",[24,909,910],{},"but the editor says the module cannot be found",[14,912,913],{},"That usually means the editor is using a different Python interpreter.",[14,915,916,917,73],{},"If needed, this can also help when learning ",[272,918,920],{"href":919},"\u002Flearn\u002Fhow-to-run-python-code-command-line-and-ides","how to run Python code from the command line and IDEs",[37,922,924],{"id":923},"deactivate-the-environment","Deactivate the environment",[14,926,927],{},"When you are done, run:",[45,929,930],{"className":47,"code":161,"language":49,"meta":50,"style":50},[52,931,932],{"__ignoreMap":50},[55,933,934],{"class":57,"line":58},[55,935,161],{"class":61},[14,937,938],{},"This returns your terminal to the global Python environment.",[14,940,941],{},"Important:",[21,943,944,954,957],{},[24,945,946,948,949,953],{},[52,947,196],{}," does ",[950,951,952],"strong",{},"not"," delete the environment",[24,955,956],{},"it only turns it off for the current terminal session",[24,958,959],{},"you can activate it again later",[37,961,963],{"id":962},"delete-and-recreate-an-environment","Delete and recreate an environment",[14,965,966,967,712],{},"If you want to remove the environment, delete the ",[52,968,175],{},[14,970,971],{},"Then recreate it with:",[45,973,974],{"className":47,"code":360,"language":49,"meta":50,"style":50},[52,975,976],{"__ignoreMap":50},[55,977,978,980,982,984,986],{"class":57,"line":58},[55,979,62],{"class":61},[55,981,66],{"class":65},[55,983,69],{"class":61},[55,985,73],{"class":72},[55,987,77],{"class":76},[14,989,990],{},"This is useful when:",[21,992,993,996,999],{},[24,994,995],{},"the environment becomes broken",[24,997,998],{},"package versions get messy",[24,1000,1001],{},"you want a clean setup",[14,1003,1004],{},"After recreating it, install your packages again.",[37,1006,1008],{"id":1007},"save-and-restore-dependencies","Save and restore dependencies",[14,1010,1011],{},"If you want to reuse the same packages later, save them to a file.",[451,1013,1015],{"id":1014},"save-installed-packages","Save installed packages",[45,1017,1019],{"className":47,"code":1018,"language":49,"meta":50,"style":50},"pip freeze > requirements.txt\n",[52,1020,1021],{"__ignoreMap":50},[55,1022,1023,1026,1029,1032,1034],{"class":57,"line":58},[55,1024,1025],{"class":61},"pip freeze ",[55,1027,1028],{"class":65},">",[55,1030,1031],{"class":61}," requirements",[55,1033,73],{"class":72},[55,1035,1036],{"class":76},"txt\n",[14,1038,1039,1040,1043],{},"This creates a ",[52,1041,1042],{},"requirements.txt"," file.",[451,1045,1047],{"id":1046},"restore-packages-later","Restore packages later",[45,1049,1051],{"className":47,"code":1050,"language":49,"meta":50,"style":50},"pip install -r requirements.txt\n",[52,1052,1053],{"__ignoreMap":50},[55,1054,1055,1058,1060,1063,1065],{"class":57,"line":58},[55,1056,1057],{"class":61},"pip install ",[55,1059,66],{"class":65},[55,1061,1062],{"class":61},"r requirements",[55,1064,73],{"class":72},[55,1066,1036],{"class":76},[14,1068,990],{},[21,1070,1071,1074,1077],{},[24,1072,1073],{},"moving the project to another computer",[24,1075,1076],{},"sharing the project with someone else",[24,1078,1079],{},"recreating the environment from scratch",[14,1081,1082],{},"A common workflow looks like this:",[45,1084,1086],{"className":47,"code":1085,"language":49,"meta":50,"style":50},"python -m venv .venv\n\n# activate the environment first\n\npip install requests\npip freeze > requirements.txt\n",[52,1087,1088,1100,1104,1109,1113,1117],{"__ignoreMap":50},[55,1089,1090,1092,1094,1096,1098],{"class":57,"line":58},[55,1091,62],{"class":61},[55,1093,66],{"class":65},[55,1095,69],{"class":61},[55,1097,73],{"class":72},[55,1099,77],{"class":76},[55,1101,1102],{"class":57,"line":80},[55,1103,84],{"emptyLinePlaceholder":83},[55,1105,1106],{"class":57,"line":87},[55,1107,1108],{"class":90},"# activate the environment first\n",[55,1110,1111],{"class":57,"line":94},[55,1112,84],{"emptyLinePlaceholder":83},[55,1114,1115],{"class":57,"line":109},[55,1116,150],{"class":61},[55,1118,1119,1121,1123,1125,1127],{"class":57,"line":114},[55,1120,1025],{"class":61},[55,1122,1028],{"class":65},[55,1124,1031],{"class":61},[55,1126,73],{"class":72},[55,1128,1036],{"class":76},[14,1130,1131],{},"Later, after deleting or recreating the environment:",[45,1133,1135],{"className":47,"code":1134,"language":49,"meta":50,"style":50},"python -m venv .venv\n\n# activate the environment first\n\npip install -r requirements.txt\n",[52,1136,1137,1149,1153,1157,1161],{"__ignoreMap":50},[55,1138,1139,1141,1143,1145,1147],{"class":57,"line":58},[55,1140,62],{"class":61},[55,1142,66],{"class":65},[55,1144,69],{"class":61},[55,1146,73],{"class":72},[55,1148,77],{"class":76},[55,1150,1151],{"class":57,"line":80},[55,1152,84],{"emptyLinePlaceholder":83},[55,1154,1155],{"class":57,"line":87},[55,1156,1108],{"class":90},[55,1158,1159],{"class":57,"line":94},[55,1160,84],{"emptyLinePlaceholder":83},[55,1162,1163,1165,1167,1169,1171],{"class":57,"line":109},[55,1164,1057],{"class":61},[55,1166,66],{"class":65},[55,1168,1062],{"class":61},[55,1170,73],{"class":72},[55,1172,1036],{"class":76},[37,1174,1176],{"id":1175},"common-problems-and-quick-fixes","Common problems and quick fixes",[451,1178,1180,1182],{"id":1179},"python-command-not-found",[52,1181,49],{}," command not found",[14,1184,1185],{},"This usually means Python is not installed correctly, or it is not on your system PATH.",[14,1187,1188],{},"Try:",[45,1190,1191],{"className":47,"code":309,"language":49,"meta":50,"style":50},[52,1192,1193],{"__ignoreMap":50},[55,1194,1195,1197,1199],{"class":57,"line":58},[55,1196,62],{"class":61},[55,1198,318],{"class":105},[55,1200,321],{"class":61},[14,1202,1203,1204,73],{},"If that fails, review ",[272,1205,1206],{"href":349},"how to install Python on Windows, macOS, and Linux",[451,1208,1210],{"id":1209},"activation-script-is-blocked-in-powershell","Activation script is blocked in PowerShell",[14,1212,1213],{},"On Windows PowerShell, you may get an execution policy error when running:",[45,1215,1216],{"className":47,"code":476,"language":49,"meta":50,"style":50},[52,1217,1218],{"__ignoreMap":50},[55,1219,1220,1222,1224,1226],{"class":57,"line":58},[55,1221,73],{"class":72},[55,1223,99],{"class":76},[55,1225,102],{"class":72},[55,1227,489],{"class":105},[14,1229,1230],{},"Quick fixes:",[21,1232,1233,1236],{},[24,1234,1235],{},"use Command Prompt instead",[24,1237,1238],{},"or adjust the PowerShell execution policy if allowed on your system",[451,1240,1242],{"id":1241},"package-installs-to-the-wrong-place","Package installs to the wrong place",[14,1244,1245,1246,1249],{},"This often happens when you run ",[52,1247,1248],{},"pip install"," before activating the environment.",[14,1251,1252],{},"Check:",[45,1254,1256],{"className":47,"code":1255,"language":49,"meta":50,"style":50},"pip --version\npython -m pip --version\n",[52,1257,1258,1266],{"__ignoreMap":50},[55,1259,1260,1262,1264],{"class":57,"line":58},[55,1261,638],{"class":61},[55,1263,318],{"class":105},[55,1265,321],{"class":61},[55,1267,1268,1270,1272,1274,1276],{"class":57,"line":80},[55,1269,62],{"class":61},[55,1271,66],{"class":65},[55,1273,659],{"class":61},[55,1275,318],{"class":105},[55,1277,321],{"class":61},[14,1279,1280,1281,1283],{},"If the path does not point into ",[52,1282,175],{},", activate the environment first.",[451,1285,1287,1290],{"id":1286},"modulenotfounderror-after-installing-a-package",[52,1288,1289],{},"ModuleNotFoundError"," after installing a package",[14,1292,1293],{},"This usually means one of these things happened:",[21,1295,1296,1299,1302],{},[24,1297,1298],{},"the package was installed in a different environment",[24,1300,1301],{},"the editor is using a different interpreter",[24,1303,1304],{},"the environment was not active during install",[14,1306,1307],{},"Related help:",[21,1309,1310,1316],{},[24,1311,1312],{},[272,1313,1315],{"href":1314},"\u002Ferrors\u002Fmodulenotfounderror-no-module-named-x-fix","ModuleNotFoundError: No module named x",[24,1317,1318],{},[272,1319,1321],{"href":1320},"\u002Ferrors\u002Fimporterror-no-module-named-x-fix","ImportError: No module named x",[37,1323,1325],{"id":1324},"common-mistakes","Common mistakes",[14,1327,1328],{},"These are the most common beginner mistakes with virtual environments:",[21,1330,1331,1334,1337,1343,1346],{},[24,1332,1333],{},"trying to install packages before activating the environment",[24,1335,1336],{},"using the wrong activation command for the operating system or shell",[24,1338,1339,1340,1342],{},"running ",[52,1341,215],{}," from the global Python instead of the environment",[24,1344,1345],{},"opening the editor with a different interpreter than the terminal",[24,1347,1348,1349,1351],{},"assuming ",[52,1350,196],{}," deletes the environment",[14,1353,1354],{},"Useful commands for checking problems:",[45,1356,1358],{"className":47,"code":1357,"language":49,"meta":50,"style":50},"python --version\npython -m venv .venv\npip --version\npython -m pip --version\npip list\n",[52,1359,1360,1368,1380,1388,1400],{"__ignoreMap":50},[55,1361,1362,1364,1366],{"class":57,"line":58},[55,1363,62],{"class":61},[55,1365,318],{"class":105},[55,1367,321],{"class":61},[55,1369,1370,1372,1374,1376,1378],{"class":57,"line":80},[55,1371,62],{"class":61},[55,1373,66],{"class":65},[55,1375,69],{"class":61},[55,1377,73],{"class":72},[55,1379,77],{"class":76},[55,1381,1382,1384,1386],{"class":57,"line":87},[55,1383,638],{"class":61},[55,1385,318],{"class":105},[55,1387,321],{"class":61},[55,1389,1390,1392,1394,1396,1398],{"class":57,"line":94},[55,1391,62],{"class":61},[55,1393,66],{"class":65},[55,1395,659],{"class":61},[55,1397,318],{"class":105},[55,1399,321],{"class":61},[55,1401,1402,1404],{"class":57,"line":109},[55,1403,638],{"class":61},[55,1405,754],{"class":753},[14,1407,673],{},[45,1409,1410],{"className":47,"code":676,"language":49,"meta":50,"style":50},[52,1411,1412,1416],{"__ignoreMap":50},[55,1413,1414],{"class":57,"line":58},[55,1415,683],{"class":61},[55,1417,1418],{"class":57,"line":80},[55,1419,688],{"class":61},[14,1421,691],{},[45,1423,1424],{"className":47,"code":694,"language":49,"meta":50,"style":50},[52,1425,1426,1430],{"__ignoreMap":50},[55,1427,1428],{"class":57,"line":58},[55,1429,701],{"class":61},[55,1431,1432],{"class":57,"line":80},[55,1433,706],{"class":61},[37,1435,1437],{"id":1436},"faq","FAQ",[451,1439,1441],{"id":1440},"do-i-need-a-virtual-environment-for-every-project","Do I need a virtual environment for every project?",[14,1443,1444],{},"For most projects, yes. It keeps packages separate and avoids version conflicts.",[451,1446,1448,1449,527,1451,1453],{"id":1447},"what-is-the-difference-between-venv-and-pip","What is the difference between ",[52,1450,99],{},[52,1452,215],{},"?",[14,1455,1456,1458,1459,1461],{},[52,1457,99],{}," creates the isolated environment. ",[52,1460,215],{}," installs packages into that environment.",[451,1463,1465,1466,301,1468,1453],{"id":1464},"should-i-name-the-folder-venv-or-venv","Should I name the folder ",[52,1467,99],{},[52,1469,175],{},[14,1471,1472,1473,1475],{},"Both work. ",[52,1474,175],{}," is common because many editors recognize it and it stays less visible.",[451,1477,1479,1480,1482],{"id":1478},"does-deactivate-remove-installed-packages","Does ",[52,1481,196],{}," remove installed packages?",[14,1484,1485],{},"No. It only stops using the environment in the current terminal session.",[451,1487,1489],{"id":1488},"can-i-share-a-virtual-environment-folder-with-other-people","Can I share a virtual environment folder with other people?",[14,1491,1492,1493,1495],{},"Usually no. Share a ",[52,1494,1042],{}," file instead, and let each person create their own environment.",[37,1497,1499],{"id":1498},"see-also","See also",[21,1501,1502,1507,1512,1517,1521],{},[24,1503,1504],{},[272,1505,1506],{"href":274},"How to install a Python package with pip",[24,1508,1509],{},[272,1510,1511],{"href":868},"How to import a module in Python",[24,1513,1514],{},[272,1515,1516],{"href":864},"How imports work in Python",[24,1518,1519],{},[272,1520,1315],{"href":1314},[24,1522,1523],{},[272,1524,1525],{"href":919},"How to run Python code from the command line and IDEs",[1527,1528,1529],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}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 .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--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 .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 .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 .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 .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 .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--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":50,"searchDepth":80,"depth":80,"links":1531},[1532,1533,1534,1535,1536,1537,1542,1549,1550,1551,1552,1553,1557,1565,1566,1576],{"id":39,"depth":80,"text":40},{"id":200,"depth":80,"text":201},{"id":241,"depth":80,"text":242},{"id":278,"depth":80,"text":279},{"id":353,"depth":80,"text":354},{"id":445,"depth":80,"text":446,"children":1538},[1539,1540,1541],{"id":453,"depth":87,"text":454},{"id":472,"depth":87,"text":473},{"id":492,"depth":87,"text":493},{"id":580,"depth":80,"text":581,"children":1543},[1544,1545,1546,1548],{"id":587,"depth":87,"text":588},{"id":608,"depth":87,"text":609},{"id":624,"depth":87,"text":1547},"Check which pip is being used",{"id":669,"depth":87,"text":670},{"id":715,"depth":80,"text":716},{"id":872,"depth":80,"text":873},{"id":923,"depth":80,"text":924},{"id":962,"depth":80,"text":963},{"id":1007,"depth":80,"text":1008,"children":1554},[1555,1556],{"id":1014,"depth":87,"text":1015},{"id":1046,"depth":87,"text":1047},{"id":1175,"depth":80,"text":1176,"children":1558},[1559,1561,1562,1563],{"id":1179,"depth":87,"text":1560},"python command not found",{"id":1209,"depth":87,"text":1210},{"id":1241,"depth":87,"text":1242},{"id":1286,"depth":87,"text":1564},"ModuleNotFoundError after installing a package",{"id":1324,"depth":80,"text":1325},{"id":1436,"depth":80,"text":1437,"children":1567},[1568,1569,1571,1573,1575],{"id":1440,"depth":87,"text":1441},{"id":1447,"depth":87,"text":1570},"What is the difference between venv and pip?",{"id":1464,"depth":87,"text":1572},"Should I name the folder venv or .venv?",{"id":1478,"depth":87,"text":1574},"Does deactivate remove installed packages?",{"id":1488,"depth":87,"text":1489},{"id":1498,"depth":80,"text":1499},"Master how to create and use a virtual environment in python in our comprehensive Python beginner guide.","md",{},"\u002Fhow-to\u002Fhow-to-create-and-use-a-virtual-environment-in-python",{"title":5,"description":1577},"how-to\u002Fhow-to-create-and-use-a-virtual-environment-in-python","EYgQrZDvrNQlWNzA9tTl48tp9iCRgu9W4GgyvD55hlk",1777585503245]