<metaname="description" content="Python web applications depend on many code libraries. Learn more about application dependencies on Full Stack Python.">
<divstyle="padding: 0 0 20px 0; margin: 0 0 20px 0; background-color: #22B24C;">
<divclass="container">
<h2style="color: #fff; margin: 20px 40px 0 0;"><ahref="https://www.gumroad.com/l/python-deployments" style="color: #fff">The Full Stack Python Guide to Deployments book</a> has been released!</h2>
</div>
</div><ahref="https://github.com/makaimc/fullstackpython.com"><imgstyle="position: absolute; top: 0; right: 0; border: 0;" src="/theme/img/fork.png" alt="Fork me on GitHub"></a>
shows the open source Python projects trending today, this week, and this
month.</p>
</li>
<li>
<p>This list of <ahref="http://freepythontips.wordpress.com/2013/07/30/20-python-libraries-you-cant-live-without/">20 Python libraries you can’t live without</a>
is a wide-ranging collection from data analysis to testing tools.</p>
</li>
<li>
<p>Wikipedia actually has an extensive
<ahref="http://en.wikipedia.org/wiki/List_of_Python_software">page dedicated to Python libraries</a>
grouped by categories.</p>
</li>
</ul>
<h2>Isolating dependencies</h2>
<p>Dependencies are installed separately from system-level packages to prevent
library version conflicts. The most common isolation method is
<ahref="http://www.virtualenv.org/en/latest/">virtualenv</a>. Each virtualenv is its
own copy of the Python interpreter and dependencies in the site-packages
directory. To use a virtualenv it must first be created with the virtualenv
command and then activated.</p>
<p>The virtualenv stores dependencies in an isolated environment. The web
application then relies only on that virtualenv instance which has a separate
copy of the Python interpreter and site-packages directory. A high level of
how a server configured with virtualenv can look is shown in the picture below.</p>
<p><imgsrc="theme/img/server-setup.png" alt="How the virtualenv separates dependencies on the server." width="100%" class="technical-diagram" /></p>
<h2>Installing Python dependencies</h2>
<p>The recommended way to install Python library dependencies is with the
<ahref="http://www.pip-installer.org/en/latest/">pip</a> command when a virtualenv
is activated.</p>
<p>Pip and virtualenv work together and have complementary responsibilities.
Pip downloads and installs application dependencies from the central
Setup.py is a standard for distributing and installing Python libraries.
If you're building a Python library, such as
<ahref="http://www.python-requests.org/en/latest/">requests</a> or
<ahref="https://github.com/makaimc/underwear">underwear</a> you must include setup.py
so a dependency manager can correctly install both the library as well as
additional dependencies for the library. There's still quite a bit of
confusion in the Python community over the difference between
requirements.txt and setup.py, so read this
<ahref="https://caremad.io/blog/setup-vs-requirement/">well written post</a> for
further clarification.</p>
<h2>Application dependency resources</h2>
<ul>
<li>
<p><ahref="https://twitter.com/jonathanchu">Jon Chu</a> wrote a great introduction on
<ahref="http://www.jontourage.com/2011/02/09/virtualenv-pip-basics/">virtualenv and pip basics</a>.</p>
</li>
<li>
<p><ahref="http://dabapps.com/blog/introduction-to-pip-and-virtualenv-python/">A non-magical introduction to virtualenv and pip</a>
breaks down what problems these tools solve and how to use them.</p>
</li>
<li>
<p><ahref="http://www.clemesha.org/blog/modern-python-hacker-tools-virtualenv-fabric-pip/">Tools of the modern Python hacker</a>
contains detailed explanations of virtualenv, Fabric, and pip.</p>
</li>
<li>
<p>Occasionally arguments about using Python's dependency manager versus
one of Linux's dependency managers comes up. This provides
<ahref="http://notes.pault.ag/debian-python/">one perspective on that debate</a>.</p>
</li>
<li>
<p>This Stack Overflow question details how to set up a
<ahref="http://askubuntu.com/questions/244641/how-to-set-up-and-use-a-virtual-python-environment-in-ubuntu">virtual environment for Python development</a>.</p>
</li>
<li>
<p>Another Stack Overflow page answers
<ahref="http://stackoverflow.com/questions/9554087/setting-an-environment-variable-in-virtualenv">how to set environment variables when using virtualenv</a>.</p>
</li>
<li>
<p><ahref="http://mrcoles.com/tips-using-pip-virtualenv-virtualenvwrapper/">Tips for using pip + virtualenv + virtualenvwrapper</a>
shows how to use shell aliases and postactivate virtualenvwrapper hooks to
make life easier when using these tools.</p>
</li>
<li>
<p>Major speed improvements were made in pip 7 over previous versions. Read
<ahref="https://lincolnloop.com/blog/fast-immutable-python-deployments/">this article about the differences</a>
and be sure to upgrade.</p>
</li>
<li>
<p><ahref="http://peterdowns.com/posts/first-time-with-pypi.html">How to submit a package to PyPI</a>
is a short and sweet introduction that'll help you quickly get your first
package on PyPI.</p>
</li>
</ul>
<h2>Open source app dependency projects</h2>
<ul>
<li>
<p><ahref="https://github.com/kennethreitz/autoenv">Autoenv</a> is a tool for activating
environment variables stored in a <code>.env</code> file in your projects' home
directories. Environment variables aren't managed by virtualenv and although
virtualenvwrapper has some hooks for handling them, it's often easiest to
use a shell script or <code>.env</code> file to set them in a development environment.</p>
</li>
<li>
<p><ahref="https://github.com/bndr/pipreqs">Pipreqs</a> searches through a project for
dependencies based on imports. It then generates a <code>requirements.txt</code> file
based on the libraries necessary to run those dependencies. Note though that
while this could come in handy with a legacy project, the version numbers
for those libraries will not be generated with the output.</p>
<ahref="http://www.deploypython.com/"><imgsrc="//static.fullstackpython.com/fsp-deployment-guide.png" alt="The Full Stack Python Guide to Deployments" width="100%"></a>
<pstyle="font-size: .8em; margin-top: 10px;">Searching for a complete, step-by-step deployment walkthrough? Learn more about <ahref="http://www.deploypython.com/">The Full Stack Python Guide to Deployments book</a>.
</p>
</div>
</div><divclass="panel panel-success">
<divclass="panel-heading">
<h3class="panel-head"><ahref="/table-of-contents.html" style="color: #fff;">Table of Contents</a></h3>
<ahref="/about-author.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>About the Author</a>
</div>
</div>
<divclass="panel panel-success">
<divclass="panel-body">
<ahref="http://www.deploypython.com/"><imgsrc="//static.fullstackpython.com/fsp-deployment-guide.png" alt="The Full Stack Python Guide to Deployments" width="100%"></a>
<pstyle="font-size: .8em; margin-top: 10px;">Searching for a complete, step-by-step deployment walkthrough? Learn more about <ahref="http://www.deploypython.com/">The Full Stack Python Guide to Deployments book</a>.