{"id":120,"date":"2017-03-26T16:32:09","date_gmt":"2017-03-26T20:32:09","guid":{"rendered":"https:\/\/packetlost.com\/blog\/?p=120"},"modified":"2017-03-26T18:07:33","modified_gmt":"2017-03-26T22:07:33","slug":"configure-visual-studio-code-to-run-python-on-windows","status":"publish","type":"post","link":"https:\/\/packetlost.com\/blog\/2017\/03\/26\/configure-visual-studio-code-to-run-python-on-windows\/","title":{"rendered":"Configure Visual Studio Code to run Python on Windows"},"content":{"rendered":"<p>Recently I was looking at my IDE options for writing some python applications. I really want to get more familiar with Visual Studio Code so I picked that to begin learning on. My only requirement was to pick an IDE I could use on both Windows and Linux. I know that many other IDEs are more polished and would be easier to configure but I wanted to challenge myself a little.<\/p>\n<p>After I downloaded the <a href=\"https:\/\/www.python.org\/downloads\/windows\/\">latest version of python<\/a>, I installed python via the executable installer. During the install there is a check box you can select to add python to your path, so I chose that option.<\/p>\n<p>Next up I downloaded <a href=\"https:\/\/code.visualstudio.com\/download\">Visual Studio Code<\/a> and also used the executable installer. Again there is an option to add Visual Studio Code to the path environment variable, so I chose that option as well. After a reboot my path looked like this.<\/p>\n<p><a href=\"https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/pathoutput.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-123 size-full\" src=\"https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/pathoutput.png\" alt=\"\" width=\"858\" height=\"146\" srcset=\"https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/pathoutput.png 858w, https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/pathoutput-300x51.png 300w, https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/pathoutput-768x131.png 768w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/a><\/p>\n<p>You can see the paths to python and Visual Studio Code are present. This should make working with these new tools a bit easier. To make sure I could run python from the shell, I went ahead and launched python from the PowerShell console and outputted some Hello World.<\/p>\n<p><a href=\"https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/pythonfrompowershell.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-124\" src=\"https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/pythonfrompowershell.png\" alt=\"\" width=\"629\" height=\"152\" srcset=\"https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/pythonfrompowershell.png 629w, https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/pythonfrompowershell-300x72.png 300w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/a><\/p>\n<p>With shell execution confirmed it was time to move on to the IDE configuration. I opened Visual Studio Code and installed the python extension. Then I opened a folder I created in My Documents for python scripts within Visual Studio Code. I had already picked up that opening up a folder in VS code was a first step to code execution from some earlier learning on Ubuntu with PowerShell and Dot NET Core. Inside that new folder, I created HelloWorld.py with a simple print Hello World line. When I went to run the HelloWorld.py with Control+Shift+B, I hit a wall. No task runner configured error. That is where I discovered I needed to configure the task runner to be able to execute python from Visual Studio Code. To configure the task runner, open the command palette either through the Menus via View -&gt; Command Palette or use the keyboard shortcut Control+Shift+P and type Task Configure, to find the configure task runner selection. Then Choose Other, and make your tasks.json look like this:<\/p>\n<pre class=\"lang:default decode:true \" title=\"tasks.json\">{\r\n    \/\/ See https:\/\/go.microsoft.com\/fwlink\/?LinkId=733558\r\n    \/\/ for the documentation about the tasks.json format\r\n    \"version\": \"0.1.0\",\r\n    \"command\": \"python\",\r\n    \"isShellCommand\": true,\r\n    \"args\": [\"${file}\"],\r\n    \"showOutput\": \"always\"\r\n}<\/pre>\n<p>All I needed to change was the &#8220;command&#8221; line to python and the &#8220;args&#8221; line to [&#8220;${file}&#8221;], once that was done I was able to execute python from Visual Studio Code as seen below.<\/p>\n<p><a href=\"https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/vscodetaskrunnerconfigured.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-125\" src=\"https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/vscodetaskrunnerconfigured-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/vscodetaskrunnerconfigured-300x225.png 300w, https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/vscodetaskrunnerconfigured-768x577.png 768w, https:\/\/packetlost.com\/blog\/wp-content\/uploads\/2017\/03\/vscodetaskrunnerconfigured.png 1006w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Credit to codingisforyou on youtube for making a <a href=\"https:\/\/www.youtube.com\/watch?v=WdGyfCceCvM\">video<\/a> covering this as well as diving a bit deeper into the debugging configuration of VS code. In his video he needed to include the full path to the python executable including escaping some of the backslash characters, which I assume is due to python not being in his environment variables.<\/p>\n<p>Now my python environment inside Visual Studio Code is all configured and actually looks like the <a href=\"https:\/\/code.visualstudio.com\/docs\/languages\/python\">Microsoft Documentation<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was looking at my IDE options for writing some python applications. I really want to get more familiar with Visual Studio Code so I picked that to begin learning on. My only requirement was to pick an IDE &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/packetlost.com\/blog\/2017\/03\/26\/configure-visual-studio-code-to-run-python-on-windows\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36,37],"tags":[41,38,40,39],"class_list":["post-120","post","type-post","status-publish","format-standard","hentry","category-python","category-visual-studio-code","tag-configure","tag-python","tag-task-runner","tag-visual-studio-code"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":5,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":129,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts\/120\/revisions\/129"}],"wp:attachment":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}