{"id":13,"date":"2023-11-24T23:30:45","date_gmt":"2023-11-25T04:30:45","guid":{"rendered":"https:\/\/coding101.xyz\/?p=13"},"modified":"2023-12-02T20:03:42","modified_gmt":"2023-12-03T01:03:42","slug":"python-virtual-environment-venv","status":"publish","type":"post","link":"https:\/\/coding101.xyz\/?p=13","title":{"rendered":"Python Virtual Environment venv"},"content":{"rendered":"\n<p>This is about virtual environments for Python. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>venv<\/strong> is the best approach to select a Python environment. Venv would provide the possibility to assign a virtual environment, activate it. This makes working multiple projects on the same machine easy. <\/p>\n\n\n\n<p>Setting venv: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -m venv folder_name<\/code><\/pre>\n\n\n\n<p>This creates a new environment to the folder specified; it creates the folder if needed. <\/p>\n\n\n\n<p>Then inside the folder there is another subfolder called bin, underneath there are links to the python executable etc. There is a script called &#8220;activate&#8221;. This is not marked executable &#8211; if you run on linux &#8211; so it has to be run with a command like <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source activate<\/code><\/pre>\n\n\n\n<p>This activates the current virtual environment for the current session. Also defines a new function called deactivate. This function can be invoked from the current session and ultimately deactivates the current virtual environment, potentially to move to another virtual environment. <\/p>\n\n\n\n<p>Below is the set of commands showing how to create a venv and then activate it. Note the &#8220;source activate&#8221; command. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"484\" height=\"157\" src=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2023\/11\/image.png\" alt=\"\" class=\"wp-image-15\"\/><\/figure>\n\n\n\n<p>See the name of the venv on the left side. Now see below that all the commands related to Python are taken from this particular venv. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"557\" height=\"115\" src=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2023\/11\/image-1.png\" alt=\"\" class=\"wp-image-16\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This is about virtual environments for Python.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coding101.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":4,"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":101,"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/101"}],"wp:attachment":[{"href":"https:\/\/coding101.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coding101.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coding101.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}