<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Fischer dot Name &#187; virtualenv</title>
	<atom:link href="http://davidfischer.name/tag/virtualenv/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidfischer.name</link>
	<description>Some Things to Some People</description>
	<lastBuildDate>Mon, 07 May 2012 16:41:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Why You Should Be Using Pip and Virtualenv</title>
		<link>http://davidfischer.name/2010/04/why-you-should-be-using-pip-and-virtualenv/</link>
		<comments>http://davidfischer.name/2010/04/why-you-should-be-using-pip-and-virtualenv/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 07:00:35 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[pip]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[virtualenv]]></category>

		<guid isPermaLink="false">http://www.davidfischer.name/?p=467</guid>
		<description><![CDATA[In a previous post, I]]></description>
			<content:encoded><![CDATA[<p>In a <a href="/2010/01/extending-distutils-for-repeatable-builds/">previous post</a>, I promised to write about <a href="http://pip.openplans.org/">Pip</a> and <a href="http://virtualenv.openplans.org/">Virtualenv</a> and I&#8217;m now finally making good. Others have <a href="http://www.b-list.org/weblog/2008/dec/15/pip/">done</a> this <a href="http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/">before</a>, but I think I have a little to add. If you develop a Python module and you don&#8217;t test it with virtualenv, don&#8217;t make your next release until you do.</p>
<h5>Configuring the environment</h5>
<p>Virtualenv creates a Python environment that is segregated from your system wide Python installation.  In this way, you can test your module without any external packages mucking up the result, add different versions of dependency packages and generally verify the exact set of requirements for your package.</p>
<p>To create the virtual environment:</p>
<pre>% virtualenv --no-site-packages testarea</pre>
<p>This creates a directory <span style="font-family: monospace">testarea/</span> that contains directories for installing modules and a Python executable. Using the virtual environment:</p>
<pre>% cd testarea
% source bin/activate</pre>
<p>Sourcing activate will set environment variables so that only modules installed under <span style="font-family: monospace">testarea/</span> are used. After setting up the environment, any desired packages can be installed (from <a href="http://pypi.python.org">pypi</a>):</p>
<pre>(testarea) % pip install rpc4django</pre>
<p>Packages can also be uninstalled, specific versions can be installed or packages can be installed from the file system, URLs or directly from source control:</p>
<pre>(testarea) % pip uninstall rpc4django
(testarea) % pip install rpc4django==0.1.6</pre>
<p>Pip is worth using over easy_install for its uninstall capabilities alone, but I should mention that pip is actively maintained while setuptools is mostly dead.</p>
<p>When you&#8217;re done with the virtual environment, simply deactivate it:</p>
<pre>(testarea) % deactivate</pre>
<h5>Do it for the tests</h5>
<p><a href="/wp-content/uploads/2010/04/virtualenv_testing.png" rel="lightbox[467]"><img src="/wp-content/uploads/2010/04/virtualenv_testing-300x229.png" alt="Testing with virtualenv" title="Testing with virtualenv and pip" width="300" height="229" style="border: 1px solid black; margin: 5px; width: 300px; float: right;" /></a><br />
While the segregated environment that virtualenv provides is extremely well suited to getting the correct environment up and running, it is just as well suited to testing your application under a variety of different package configurations. With pip and virtualenv, testing your application under three different versions of Django is a snap and it doesn&#8217;t affect your system environment in the slightest. </p>
<h5>Dependencies made easy</h5>
<p>My favorite feature of pip is the ability to create a requirements file based on a set of packages installed in your virtual environment (or your global site-packages). Creating a requirements file can be done automatically using the <span style="font-family: monospace">freeze</span> command for pip:</p>
<pre>(testarea) % pip freeze > requirements.txt
(testarea) % more requirements.txt
Django==1.1.1
rpc4django==0.1.7
wsgiref==0.1.2</pre>
<p>Wsgiref will always appear in pip&#8217;s output. It is a <a href="http://docs.python.org/library/wsgiref.html">standard library</a> package that includes <a href="http://guide.python-distribute.org/installation.html#listing-installed-packages">package metadata</a>. The requirements file is used as follows:</p>
<pre>% pip install -r requirements.txt</pre>
<p>The requirements file can be version controlled both to aid in installation and to capture the exact versions of your dependencies directly where they are used rather than after the fact in documentation that can easily become out of date. The requirements file can be used to rebuild a virtual environment or to deploy a virtual environment into the machine&#8217;s site-packages. Pip and virtualenv are exceptionally easy to use and there&#8217;s really no excuse for a Python packager not to use them. </p>
<p><strong>Note:</strong> I&#8217;m working on a fairly large sized application for work. When it is finished, I will release a post-mortem that will also function as an update to my post about <a href="/2009/07/packaging-and-sharing-django-applications/">packaging and distributing</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidfischer.name/2010/04/why-you-should-be-using-pip-and-virtualenv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

