{"id":4731,"date":"2024-10-24T19:38:38","date_gmt":"2024-10-24T18:38:38","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4731"},"modified":"2024-10-24T19:39:34","modified_gmt":"2024-10-24T18:39:34","slug":"virtual-environment-in-vs-code-for-windows","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/virtual-environment\/virtual-environment-in-vs-code-for-windows","title":{"rendered":"Virtual environment in VS Code for Windows"},"content":{"rendered":"\n<p>Creating a virtual environment is good practice anyway for Python development in general, as it helps to manage dependencies and avoid conflicts.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create virtual environment<\/h4>\n\n\n\n<p>Use the Command Palette (CTRL+SHIFT+P) to open a new terminal session with \u201cTerminal: Create New Terminal\u201d.<\/p>\n\n\n\n<p>Then create a new virtual environment by running the following commands in the terminal:<\/p>\n\n\n\n<p>python -m venv .venv &#8211;system-site-packages<br>source .venv\/bin\/activate<br>python -m pip install &#8211;upgrade pip setuptools wheel<\/p>\n\n\n\n<p>VSCode will ask &#8220;We noticed a new environment has been created. Do you want to select it for the workspace folder&#8221;<br>Click &#8220;Yes&#8221;<\/p>\n\n\n\n<p>The \u201c\u2013system-site-packages\u201d is an optional argument which means that the virtual environment will also have access to the system site-packages dir (see here)<\/p>\n\n\n\n<p>The virtual environment will be created in a folder called &#8220;.venv&#8221; (you don&#8217;t need to put your project files in it).<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">GitHub<\/h5>\n\n\n\n<p>Make sure to update your &#8216;gitignore to prevent committing your virtual environment.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Selecting the environment to be used<\/h4>\n\n\n\n<p>Use the Command Palette (CTRL+SHIFT+P) Python: Select Interpreter<br>Select the &#8220;.venv&#8221; one<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Install a package<\/h5>\n\n\n\n<p>Ensure pip is up to date:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python.exe -m pip install --upgrade pip<\/code><\/pre>\n\n\n\n<p>In the terminal window just use a normal pip install command, e.g.:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip3 install ultralytics<\/code><\/pre>\n\n\n\n<p>(It will get installed in \\.venv.Lib\\site-packages)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creating a virtual environment is good practice anyway for Python development in general, as it helps to manage dependencies and avoid conflicts. Create virtual environment Use the Command Palette (CTRL+SHIFT+P) to open a new terminal session with \u201cTerminal: Create New Terminal\u201d. Then create a new virtual environment by running the following commands in the terminal: [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[373],"tags":[],"class_list":["post-4731","post","type-post","status-publish","format-standard","hentry","category-virtual-environment"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4731","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=4731"}],"version-history":[{"count":7,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4731\/revisions"}],"predecessor-version":[{"id":4738,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4731\/revisions\/4738"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}