{"id":485,"date":"2023-10-04T23:46:04","date_gmt":"2023-10-04T23:46:04","guid":{"rendered":"https:\/\/python.garden\/?p=485"},"modified":"2023-10-17T12:07:18","modified_gmt":"2023-10-17T12:07:18","slug":"untangling-the-virtual-environment-in-python-on-macos-a-guide-for-absolute-beginners","status":"publish","type":"post","link":"https:\/\/python.garden\/index.php\/2023\/10\/04\/untangling-the-virtual-environment-in-python-on-macos-a-guide-for-absolute-beginners\/","title":{"rendered":"Untangling the Virtual Environment in Python on macOS: A Guide for Absolute Beginners"},"content":{"rendered":"\n<p>If you&#8217;re new to Python and using a Mac, the term &#8220;Virtual Environment&#8221; might sound a bit confusing. This guide is designed to simplify the concept, focusing specifically on the macOS environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a Virtual Environment?<\/h2>\n\n\n\n<p>A Virtual Environment is like a separate room for each of your Python projects. Imagine having multiple closets for different types of clothes. Just like each closet would contain specific items, each Virtual Environment contains its own set of Python libraries and tools.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use a Virtual Environment?<\/h2>\n\n\n\n<p>Using Virtual Environments allows you to isolate project-specific libraries and versions. This way, you avoid conflicts between projects that require different versions of the same library.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Types of Virtual Environments<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. venv<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Built into Python<\/strong>: No extra installations needed.<\/li>\n\n\n\n<li><strong>Beginner-Friendly<\/strong>: Simple and straightforward to use.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. virtualenv<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>More Features<\/strong>: Options for custom prompts, different Python interpreters, etc.<\/li>\n\n\n\n<li><strong>Requires Installation<\/strong>: You have to install it separately.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. conda<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Comprehensive<\/strong>: Ideal for data science and complex projects.<\/li>\n\n\n\n<li><strong>Separate Installation<\/strong>: Comes with Anaconda or Miniconda distributions.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to Install a Virtual Environment<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">For venv<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open your Terminal app.<\/li>\n\n\n\n<li>Navigate to your project folder using <code>cd your_project_folder<\/code>.<\/li>\n\n\n\n<li>Run <code>python3 -m venv your_environment_name<\/code>.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">For virtualenv<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open Terminal and install virtualenv with <code>pip install virtualenv<\/code>.<\/li>\n\n\n\n<li>Navigate to your project folder.<\/li>\n\n\n\n<li>Run <code>virtualenv your_environment_name<\/code>.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">For conda<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Download and install Anaconda or Miniconda.<\/li>\n\n\n\n<li>Open a new Terminal window.<\/li>\n\n\n\n<li>Run <code>conda create --name your_environment_name<\/code>.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">How to List Virtual Environments<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"900\" src=\"https:\/\/i0.wp.com\/python.garden\/wp-content\/uploads\/2023\/10\/STJDccRwQSy6uK4UPN5Nkg.jpg?resize=900%2C900&#038;ssl=1\" alt=\"\" class=\"wp-image-511\" style=\"aspect-ratio:1;width:134px;height:auto\" srcset=\"https:\/\/i0.wp.com\/python.garden\/wp-content\/uploads\/2023\/10\/STJDccRwQSy6uK4UPN5Nkg.jpg?w=1024&amp;ssl=1 1024w, https:\/\/i0.wp.com\/python.garden\/wp-content\/uploads\/2023\/10\/STJDccRwQSy6uK4UPN5Nkg.jpg?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/python.garden\/wp-content\/uploads\/2023\/10\/STJDccRwQSy6uK4UPN5Nkg.jpg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/python.garden\/wp-content\/uploads\/2023\/10\/STJDccRwQSy6uK4UPN5Nkg.jpg?resize=768%2C768&amp;ssl=1 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">For venv and virtualenv<\/h3>\n\n\n\n<p>macOS doesn&#8217;t provide a built-in command to list virtual environments. You&#8217;ll need to manually check the directory where you\u2019ve stored them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">For conda<\/h3>\n\n\n\n<p>Run <code>conda env list<\/code> or <code>conda info --envs<\/code> in the Terminal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Manage Virtual Environments<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">To Activate:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>venv and virtualenv<\/strong>: In the Terminal, run <code>source your_environment_name\/bin\/activate<\/code>.<\/li>\n\n\n\n<li><strong>conda<\/strong>: Run <code>conda activate your_environment_name<\/code> in the Terminal.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">To Deactivate:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>venv and virtualenv<\/strong>: Just type <code>deactivate<\/code> and press Enter.<\/li>\n\n\n\n<li><strong>conda<\/strong>: Run <code>conda deactivate<\/code> in the Terminal.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">In Summary<\/h2>\n\n\n\n<p>Understanding and using Virtual Environments in Python on macOS helps you maintain cleaner and conflict-free projects. Whether you go with venv, virtualenv, or conda, the ultimate aim is to segregate your projects and their dependencies neatly.<\/p>\n\n\n\n<p>Congratulations, you\u2019ve successfully untangled the concept of a Virtual Environment in Python on macOS. Now, you\u2019re ready to manage your Python projects more effectively. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re new to Python and using a Mac, the term &#8220;Virtual Environment&#8221; might sound a bit confusing. This guide is designed to simplify the concept, focusing specifically on the&hellip;<\/p>\n","protected":false},"author":1,"featured_media":509,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-485","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"featured_image_src":"https:\/\/i0.wp.com\/python.garden\/wp-content\/uploads\/2023\/10\/qu7kC29lQPSm5TehYF03jQ.jpg?fit=256%2C256&ssl=1","author_info":{"display_name":"shababdoo","author_link":"https:\/\/python.garden\/index.php\/author\/shababdoo\/"},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/python.garden\/wp-content\/uploads\/2023\/10\/qu7kC29lQPSm5TehYF03jQ.jpg?fit=256%2C256&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/posts\/485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/comments?post=485"}],"version-history":[{"count":0,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/posts\/485\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/media\/509"}],"wp:attachment":[{"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/media?parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/categories?post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python.garden\/index.php\/wp-json\/wp\/v2\/tags?post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}