{"id":4343,"date":"2023-11-14T12:31:44","date_gmt":"2023-11-14T12:31:44","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4343"},"modified":"2024-10-07T14:50:23","modified_gmt":"2024-10-07T13:50:23","slug":"visual-studio-code","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/python-on-windows\/visual-studio-code\/visual-studio-code","title":{"rendered":".3 Using Visual Studio Code"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Resources<\/h4>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/code.visualstudio.com\/docs\/python\/python-tutorial\" target=\"_blank\">https:\/\/code.visualstudio.com\/docs\/python\/python-tutorial<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Creating a new Python project<\/h4>\n\n\n\n<p>VS Code menu &gt; File &gt; Open Folder<\/p>\n\n\n\n<p>Open a folder that will be your workspace (you can just open an empty folder you&#8217;ve created).<\/p>\n\n\n\n<p>Turn off Dropbox if your folder is within Dropbox (causes file access issues for us at times)<\/p>\n\n\n\n<p>Now create a virtual environment for this project (recommended approach when using Python, so individual projects and their dependencies are kept isolated from each other).<br>Open the Command Palette (Ctrl+Shift+P) and enter &#8220;Python: Create Environment&#8221;<br>Select &#8220;Venv&#8221; (default, or whatever you want to use)<br>Select the interpreter to use (the version of Python you&#8217;ve installed on your machine).<br>Wait for the progress to complete. Check for any errors.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Create a new file<\/h5>\n\n\n\n<p>Menu &gt; File &gt; New file&#8230; &gt; MyFileName.py<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Running the Project<\/h4>\n\n\n\n<p>Use the play button at the top right of the code editor window &#8220;Run Python File&#8221;.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Debugging the project<\/h4>\n\n\n\n<p>Press F5<\/p>\n\n\n\n<p>Or use the dropdown option on the play button at the top right of the code editor window and select &#8220;Debug Python File&#8221;.<\/p>\n\n\n\n<p>Then use menu > Run options to control debugging.<\/p>\n\n\n\n<p>There is also the left &#8220;Run and Debug&#8221; panel which shows various debug info.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Install python packages you want to use in your code<\/h4>\n\n\n\n<p>Open the Command Palette (Ctrl+Shift+P) and enter &#8220;Terminal: Create New Terminal&#8221; to create a powershell terminal window.<\/p>\n\n\n\n<p>Say you want to install the &#8220;requests&#8221; python package:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>py -m pip install requests<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Troubleshooting<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">If there are errors creating the virtual environment<\/h5>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/code.visualstudio.com\/docs\/python\/environments#_creating-environments\" target=\"_blank\">This page may help<\/a><\/p>\n\n\n\n<p>Right click the Output window and select &#8220;Clear output&#8221; before trying again, so you are not looking at old errors.<\/p>\n\n\n\n<p>If you make changes to try and fix, you can delete the .venv directory and try again (seems to work better than telling VS code to do it when running &#8220;Python: Create Environment&#8221; again in our experience).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Resources https:\/\/code.visualstudio.com\/docs\/python\/python-tutorial Creating a new Python project VS Code menu &gt; File &gt; Open Folder Open a folder that will be your workspace (you can just open an empty folder you&#8217;ve created). Turn off Dropbox if your folder is within Dropbox (causes file access issues for us at times) Now create a virtual environment for [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[370],"tags":[],"class_list":["post-4343","post","type-post","status-publish","format-standard","hentry","category-visual-studio-code"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4343"}],"version-history":[{"count":24,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4343\/revisions"}],"predecessor-version":[{"id":4701,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4343\/revisions\/4701"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}