<?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: George Roros</title>
    <description>The latest articles on Forem by George Roros (@geopopos).</description>
    <link>https://forem.com/geopopos</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%2F122516%2Fbc219587-c016-473c-a556-89e7cb839045.jpeg</url>
      <title>Forem: George Roros</title>
      <link>https://forem.com/geopopos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/geopopos"/>
    <language>en</language>
    <item>
      <title>Random Python Tutorials: Up and Running With virtualenv</title>
      <dc:creator>George Roros</dc:creator>
      <pubDate>Tue, 17 Sep 2019 03:21:48 +0000</pubDate>
      <link>https://forem.com/geopopos/random-python-tutorials-up-and-running-with-virtualenv-3lah</link>
      <guid>https://forem.com/geopopos/random-python-tutorials-up-and-running-with-virtualenv-3lah</guid>
      <description>&lt;p&gt;If you have ever managed multiple python projects on a single machine, you may have run into a problem where you have different projects using different versions of a particular package. You update the package for the latest project you are working on, you then switch back to an older project and BOOM, dependency errors, everyone's favorite.&lt;/p&gt;

&lt;p&gt;In this article, I will be giving a brief intro to getting up and running with virtualenv on your system.&lt;/p&gt;

&lt;p&gt;virtualenv is a tool used to create and manage multiple python environments, so that you don't have to worry about overlapping packages.&lt;/p&gt;

&lt;p&gt;The tool works by creating a fresh python installation where you specify&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Installing virtualenv
&lt;/h2&gt;

&lt;p&gt;To install virtualenv via pip:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install virtualenv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Check your installation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ virtualenv --version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Creating your first virtual environment with venv
&lt;/h2&gt;

&lt;p&gt;Let's make a test_project/ folder to create our virtual environment in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir test_project/
$ cd test_project/
$ virtualenv venv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;virtualenv&lt;/code&gt; command takes an argument, &lt;code&gt;DEST_DIR&lt;/code&gt;, which is the directory in which your virtual environment will be created. We created our environment in &lt;code&gt;venv&lt;/code&gt; if you do not specify a destination directory virtualenv will place the files in the current directory&lt;/p&gt;

&lt;p&gt;to use the virtual environment it must be activated&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ source venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;if you used a name other than &lt;code&gt;venv&lt;/code&gt; you should substitute it in the above command (ex: &lt;code&gt;source [folder_name]/bin/activate&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;you should see &lt;code&gt;(venv)&lt;/code&gt; in front of your default shell.&lt;/p&gt;

&lt;p&gt;now that we have activated our virtual environment let's install a package using pip&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install requests
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;now run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip freeze
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;you should see the &lt;code&gt;requests&lt;/code&gt; package is installed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;certifi==2019.9.11
chardet==3.0.4
idna==2.8
requests==2.22.0
urllib3==1.25.3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;now let's deactivate the virtual environment and check the installed packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ deactivate
$ pip freeze
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you have not installed the &lt;code&gt;requests&lt;/code&gt; package prior to this tutorial, you should not see it in the list of installed packages&lt;/p&gt;

&lt;p&gt;What happened here is when you ran deactivate you are put back in the system's default Python Interpreter instead of the virtual environment's.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;requests&lt;/code&gt; package was installed in the virtual environment.&lt;/p&gt;




&lt;p&gt;Thanks for taking the time to read! If you have any questions, comments, or concerns I would love to hear them!&lt;/p&gt;

</description>
      <category>virtualenv</category>
      <category>python</category>
      <category>virtualenvironment</category>
      <category>dependencymanagement</category>
    </item>
  </channel>
</rss>
