<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jaikish</title>
    <description>The latest articles on Forem by Jaikish (@jaikishpai).</description>
    <link>https://forem.com/jaikishpai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F84930%2Fea11f762-db8f-4cb7-8fd6-d67e2ec99596.jpeg</url>
      <title>Forem: Jaikish</title>
      <link>https://forem.com/jaikishpai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jaikishpai"/>
    <language>en</language>
    <item>
      <title>Mastering Python Development Environments: A Comprehensive Guide to Virtual Environments</title>
      <dc:creator>Jaikish</dc:creator>
      <pubDate>Wed, 27 Dec 2023 18:11:27 +0000</pubDate>
      <link>https://forem.com/jaikishpai/virtual-environment-for-python-development-16jb</link>
      <guid>https://forem.com/jaikishpai/virtual-environment-for-python-development-16jb</guid>
      <description>&lt;p&gt;Python has been my go-to programming language since I started coding. Python, as a programming language, needs little introduction. Virtual environments in Python are essential for isolating project dependencies, ensuring compatibility, and maintaining clean, reproducible development environments. They allow developers to manage specific package versions for each project, avoiding conflicts and facilitating collaboration by providing encapsulated spaces for code development.&lt;/p&gt;

&lt;p&gt;There are several ways to create a virtual environment for a Python project, and I would like to share some thoughts on three different methods that I have explored to date:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/venv.html" rel="noopener noreferrer"&gt;venv&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment" rel="noopener noreferrer"&gt;conda&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/pipenv" rel="noopener noreferrer"&gt;pipenv&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;venv&lt;/strong&gt;-  It is a Python module (3.3 and higher). This module allows the creation of lightweight "virtual environments," each with its own Python packages. Based on an existing Python installation, a virtual environment creates a "base" Python environment whose packages are isolated from those in the base environment, making the virtual environment available only to those explicitly installed in it.&lt;br&gt;
Steps to create a virtual environment using &lt;code&gt;venv&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a virtual environment using the following command with the name &lt;code&gt;myenv&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -m venv path\to\myenv`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;To activate the virtual environment:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;path\to\myenv\Scripts\activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Deactivate the virtual environment using the following command:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deactivate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Conda&lt;/strong&gt;-  It is an open-source package management system for Windows, macOS, and Linux. Developed by Anaconda, Inc., Conda simplifies installing, managing, and updating packages and environments. &lt;br&gt;
Conda is particularly popular in the data science community, but I have been using it for software development purposes.&lt;/p&gt;

&lt;p&gt;Steps to create a virtual environment using &lt;code&gt;conda&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;a href="https://docs.anaconda.com/free/anaconda/install/index.html" rel="noopener noreferrer"&gt;Anaconda&lt;/a&gt; or &lt;a href="https://docs.conda.io/projects/miniconda/en/latest/" rel="noopener noreferrer"&gt;Miniconda&lt;/a&gt; on the machine.&lt;/li&gt;
&lt;li&gt;Run the below command. &lt;code&gt;myenv&lt;/code&gt; is the virtual environment name.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;conda create --name myenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Activate the virtual environment using the following command:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;conda activate myenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Use &lt;code&gt;conda&lt;/code&gt; to install, update and manage packages. Deactivate the virtual environment using the following  command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;conda deactivate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;pipenv&lt;/strong&gt;-It brings together the most desirable features of other packaging tools, such as pip, virtualenv, and requirements.txt, into a single, cohesive tool. Pipenv uses a Pipfile to manage project dependencies, allowing deterministic builds and simplified dependency tracking. It is easy to use and provides a consistent experience when working with Python packages. Pipenv integrates package installation and virtual environment creation into a single command, providing a seamless and user-friendly experience.&lt;/p&gt;

&lt;p&gt;Steps to create a virtual environment using &lt;code&gt;pipenv&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;code&gt;pipenv&lt;/code&gt; using the &lt;code&gt;pip&lt;/code&gt; command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install pipenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Navigate to the project directory&lt;/li&gt;
&lt;li&gt;Create a virtual environment using the below command.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipenv install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command create a virtual environment with the name of the project and installs the projects dependencies based on the &lt;code&gt;Pipfile&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Activate the virtual environment using the following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipenv shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install packages for the project use the following command which will install the package and also add the package to &lt;code&gt;Pipfile&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipenv install package_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Deactivate the &lt;code&gt;pipenv&lt;/code&gt; virtual environment using the command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My experience using Conda was extensive until I came across Pipenv, which seemed like it would be a good tool for managing packages. Pipenv streamlines the workflow by integrating the creation of virtual environments and package management into one tool.&lt;/p&gt;

&lt;p&gt;I would be interested in learning about other tools for managing virtual environments.&lt;/p&gt;

&lt;p&gt;If you enjoyed my content and would like to show support, you have the option to &lt;a href="https://www.buymeacoffee.com/jpai" rel="noopener noreferrer"&gt;Buy Me a Coffee&lt;/a&gt;. Your contribution would serve as encouragement for me to create more similar stories in the future.&lt;/p&gt;

</description>
      <category>python</category>
      <category>conda</category>
      <category>pipenv</category>
      <category>virtualenvironment</category>
    </item>
  </channel>
</rss>
