{"id":37279,"date":"2024-11-01T09:56:18","date_gmt":"2024-11-01T09:56:18","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37279"},"modified":"2024-11-01T11:48:20","modified_gmt":"2024-11-01T11:48:20","slug":"python-virtual-environment-understanding-python-virtual-environments","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37279\/","title":{"rendered":"python virtual environment, understanding python virtual environments"},"content":{"rendered":"<p><body><\/p>\n<header>\n<p>This post will explain the concept and necessity of Python virtual environments, as well as how to create and manage them in detail. I will provide sufficient example code and practice to effectively utilize virtual environments.<\/p>\n<\/header>\n<section>\n<h2>1. What is a Python Virtual Environment?<\/h2>\n<p>A Python Virtual Environment is an independent environment that allows different projects to be maintained without being affected by each other&#8217;s dependencies. Since each project may require different library versions or dependencies, creating such virtual environments helps prevent issues.<\/p>\n<p>For example, if two projects use different versions of the same library, without a virtual environment, there&#8217;s a risk that these projects may fail due to conflicts. With a virtual environment, each project can manage its libraries independently.<\/p>\n<\/section>\n<section>\n<h2>2. Advantages of Virtual Environments<\/h2>\n<ul>\n<li><strong>Independence between projects:<\/strong> Each project is managed independently, so changes in one project do not affect others.<\/li>\n<li><strong>Dependency management:<\/strong> You can install and manage packages individually for each virtual environment, making it easier to resolve dependency issues.<\/li>\n<li><strong>Environment reproducibility:<\/strong> Using virtual environments makes it easy to reproduce the same environment on different systems.<\/li>\n<li><strong>Version control:<\/strong> You can pin the version of specific packages, preventing unintended behavior.<\/li>\n<\/ul>\n<\/section>\n<section>\n<h2>3. Creating and Managing Virtual Environments<\/h2>\n<p>There are several ways to create a virtual environment, but using the <em>venv<\/em> module provided by the Python standard library is the most common method. This section explains the process of creating a virtual environment.<\/p>\n<h3>3.1. Creating a Virtual Environment<\/h3>\n<pre><code>python -m venv myenv<\/code><\/pre>\n<p>The above command creates a new virtual environment named &#8220;myenv&#8221; in the current directory. By default, the created virtual environment includes <strong>python<\/strong> and <strong>pip<\/strong>.<\/p>\n<h3>3.2. Activating the Virtual Environment<\/h3>\n<ul>\n<li>Windows:\n<pre><code>myenv\\Scripts\\activate<\/code><\/pre>\n<\/li>\n<li>macOS\/Linux:\n<pre><code>source myenv\/bin\/activate<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>When the virtual environment is activated, the terminal prompt changes to indicate the currently active environment. In this state, any packages installed will be installed within the virtual environment.<\/p>\n<h3>3.3. Installing Packages<\/h3>\n<p>To install packages while the virtual environment is active, you can use the following command.<\/p>\n<pre><code>pip install package_name<\/code><\/pre>\n<p>For example, if you want to install a package called <strong>requests<\/strong>, you would enter the following:<\/p>\n<pre><code>pip install requests<\/code><\/pre>\n<h3>3.4. Viewing Installed Packages<\/h3>\n<p>You can view the list of installed packages using the following command:<\/p>\n<pre><code>pip list<\/code><\/pre>\n<h3>3.5. Deactivating the Virtual Environment<\/h3>\n<p>After using the virtual environment, you can deactivate it by entering the following command:<\/p>\n<pre><code>deactivate<\/code><\/pre>\n<h3>3.6. Deleting the Virtual Environment<\/h3>\n<p>If you no longer need the virtual environment, you can remove it by deleting the corresponding folder. The deletion process is the same as deleting a regular folder:<\/p>\n<pre><code>rm -rf myenv   # macOS\/Linux\nrmdir \/S myenv   # Windows<\/code><\/pre>\n<\/section>\n<section>\n<h2>4. requirements.txt File<\/h2>\n<p>A <strong>requirements.txt<\/strong> file is used to manage the list of packages needed for a project. This file lists all the packages required by the project, helping other developers or users easily reproduce the same environment.<\/p>\n<h3>4.1. Creating a requirements.txt File<\/h3>\n<p>To save the list of packages installed in the current virtual environment to a requirements.txt file, enter the following command:<\/p>\n<pre><code>pip freeze &gt; requirements.txt<\/code><\/pre>\n<h3>4.2. Installing Packages from a requirements.txt File<\/h3>\n<p>To allow other developers to reproduce the same environment, packages can be installed using the requirements.txt file:<\/p>\n<pre><code>pip install -r requirements.txt<\/code><\/pre>\n<\/section>\n<section>\n<h2>5. Managing Virtual Environments with Other Tools<\/h2>\n<p>In addition to the venv module, various tools can be used to create and manage virtual environments in Python. Some of the prominent tools are <strong>conda<\/strong> and <strong>virtualenv<\/strong>.<\/p>\n<h3>5.1. Conda<\/h3>\n<p>Conda is a popular tool for environment management and package management. It is widely used in scientific computing and data science. One of the advantages of Conda is that it can manage packages for multiple programming languages, not just Python.<\/p>\n<pre><code>conda create --name myenv python=3.8<\/code><\/pre>\n<p>This command creates a virtual environment, and it can be activated as follows:<\/p>\n<pre><code>conda activate myenv<\/code><\/pre>\n<h3>5.2. virtualenv<\/h3>\n<p>virtualenv is an older tool than venv, supporting various Python versions and providing many customization options. The process to create a virtual environment after installation is as follows:<\/p>\n<pre><code>pip install virtualenv\nvirtualenv myenv<\/code><\/pre>\n<\/section>\n<section>\n<h2>6. Conclusion<\/h2>\n<p>Virtual environments are essential for managing Python projects. They allow easy management of various packages and dependencies and help prevent conflicts between projects. By utilizing virtual environments, developers can work more efficiently and smoothly.<\/p>\n<p>This tutorial explained the concept, advantages, and management methods of virtual environments. By utilizing various tools and methods, I hope you can optimize your Python development environment.<\/p>\n<\/section>\n<footer>\n<h3>References<\/h3>\n<ul>\n<li><a href=\"https:\/\/docs.python.org\/3\/tutorial\/venv.html\">Python Official Documentation: venv<\/a><\/li>\n<li><a href=\"https:\/\/packaging.python.org\/guides\/installing-using-pip-and-virtual-environments\/\">Packaging Python Projects<\/a><\/li>\n<li><a href=\"https:\/\/docs.conda.io\/projects\/conda\/en\/latest\/user-guide\/index.html\">Conda Documentation<\/a><\/li>\n<\/ul>\n<\/footer>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post will explain the concept and necessity of Python virtual environments, as well as how to create and manage them in detail. I will provide sufficient example code and practice to effectively utilize virtual environments. 1. What is a Python Virtual Environment? A Python Virtual Environment is an independent environment that allows different projects &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37279\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;python virtual environment, understanding python virtual environments&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[98],"tags":[],"class_list":["post-37279","post","type-post","status-publish","format-standard","hentry","category--en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>python virtual environment, understanding python virtual environments - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/37279\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"python virtual environment, understanding python virtual environments - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"This post will explain the concept and necessity of Python virtual environments, as well as how to create and manage them in detail. I will provide sufficient example code and practice to effectively utilize virtual environments. 1. What is a Python Virtual Environment? A Python Virtual Environment is an independent environment that allows different projects &hellip; \ub354 \ubcf4\uae30 &quot;python virtual environment, understanding python virtual environments&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37279\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:56:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:48:20+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/37279\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37279\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"python virtual environment, understanding python virtual environments\",\"datePublished\":\"2024-11-01T09:56:18+00:00\",\"dateModified\":\"2024-11-01T11:48:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37279\/\"},\"wordCount\":679,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Python Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37279\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37279\/\",\"name\":\"python virtual environment, understanding python virtual environments - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:56:18+00:00\",\"dateModified\":\"2024-11-01T11:48:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37279\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37279\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37279\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"python virtual environment, understanding python virtual environments\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"python virtual environment, understanding python virtual environments - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/37279\/","og_locale":"ko_KR","og_type":"article","og_title":"python virtual environment, understanding python virtual environments - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"This post will explain the concept and necessity of Python virtual environments, as well as how to create and manage them in detail. I will provide sufficient example code and practice to effectively utilize virtual environments. 1. What is a Python Virtual Environment? A Python Virtual Environment is an independent environment that allows different projects &hellip; \ub354 \ubcf4\uae30 \"python virtual environment, understanding python virtual environments\"","og_url":"https:\/\/atmokpo.com\/w\/37279\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:56:18+00:00","article_modified_time":"2024-11-01T11:48:20+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/37279\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37279\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"python virtual environment, understanding python virtual environments","datePublished":"2024-11-01T09:56:18+00:00","dateModified":"2024-11-01T11:48:20+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37279\/"},"wordCount":679,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Python Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37279\/","url":"https:\/\/atmokpo.com\/w\/37279\/","name":"python virtual environment, understanding python virtual environments - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:56:18+00:00","dateModified":"2024-11-01T11:48:20+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37279\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37279\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37279\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"python virtual environment, understanding python virtual environments"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=37279"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37279\/revisions"}],"predecessor-version":[{"id":37280,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37279\/revisions\/37280"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}