|
74 | 74 | <div class="row"> |
75 | 75 | <div class="col-md-8"> |
76 | 76 | <h1>Application Dependencies</h1> |
77 | | -<p>Application dependencies are the Python libraries and their versions |
78 | | -required for an application to work properly. These dependencies are |
79 | | -installed separately from system-level packages to prevent library version |
80 | | -conflicts.</p> |
81 | | -<p>The most common way to install Python library dependencies is with |
82 | | -the <a href="http://www.pip-installer.org/en/latest/">pip</a> |
83 | | -command combined with |
84 | | -<a href="http://www.virtualenv.org/en/latest/">virtualenv</a> to isolate the |
85 | | -dependencies of individual applications from each other.</p> |
| 77 | +<p>Application dependencies are the libraries other than your project code |
| 78 | +that are required to create and run your application. </p> |
| 79 | +<h2>Why are application dependencies important?</h2> |
| 80 | +<p>Python web applications are built upon the work done by thousands of open |
| 81 | +source programmers. Application dependencies include not only web frameworks but |
| 82 | +also libraries for scraping, parsing, processing, analyzing, visualizing, |
| 83 | +and myriad other tasks. Python's ecosystem facilitates discovery, retrieval and |
| 84 | +installation so applications are easier for developers to create.</p> |
| 85 | +<h2>Finding libraries</h2> |
| 86 | +<p>Python libraries are stored in a central location known as the |
| 87 | +<a href="https://pypi.python.org/pypi">Python Package Index</a> (PyPi). PyPi contains |
| 88 | +search functionality with results weighted by usage and relevance based on |
| 89 | +keyword terms.</p> |
| 90 | +<h2>Isolating application dependencies</h2> |
| 91 | +<p>Dependencies are installed separately from system-level packages to prevent |
| 92 | +library version conflicts. The most common isolation method is |
| 93 | +<a href="http://www.virtualenv.org/en/latest/">virtualenv</a>. Each virtualenv is its |
| 94 | +own copy of the Python interpreter and depedencies in the site-packages |
| 95 | +directory. To use a virtualenv it must first be created with the virtualenv |
| 96 | +command and then activated.</p> |
| 97 | +<h2>Downloading and installing Python dependencies</h2> |
| 98 | +<p>The recommended way to install Python library dependencies is with the |
| 99 | +<a href="http://www.pip-installer.org/en/latest/">pip</a> command when a virtualenv |
| 100 | +is activated.</p> |
86 | 101 | <p>Pip and virtualenv work together and have complementary responsibilities. |
87 | 102 | Pip downloads and installs application dependencies from the central |
88 | | -<a href="https://pypi.python.org/pypi">PyPi</a> repository. Virtualenv creates an |
89 | | -isolated Python installation is where those dependencies are installed into.</p> |
| 103 | +<a href="https://pypi.python.org/pypi">PyPi</a> repository. </p> |
90 | 104 | <h2>requirements.txt</h2> |
91 | 105 | <p>The pip convention for specifying application dependencies is with a |
92 | 106 | <a href="http://www.pip-installer.org/en/1.4.1/cookbook.html#requirements-files">requirements.txt</a> |
93 | 107 | file. When you build a Python web application you should include a |
94 | | -requirements.txt file with |
95 | | -<a href="https://devcenter.heroku.com/articles/python-pip">pegged dependencies</a>.</p> |
| 108 | +requirements.txt file. </p> |
| 109 | +<h3>requirementst.txt example with pegged dependencies</h3> |
| 110 | +<p>Python projects' dependencies for a web application should be specified in the |
| 111 | +requirements.txt with |
| 112 | +<a href="https://devcenter.heroku.com/articles/python-pip">pegged dependencies</a> like |
| 113 | +the following:</p> |
| 114 | +<div class="codehilite"><pre><span class="n">django</span><span class="o">==</span><span class="mf">1.6</span> |
| 115 | +<span class="n">bpython</span><span class="o">==</span><span class="mf">0.12</span> |
| 116 | +<span class="n">django</span><span class="o">-</span><span class="n">braces</span><span class="o">==</span><span class="mf">0.2.1</span> |
| 117 | +<span class="n">django</span><span class="o">-</span><span class="n">model</span><span class="o">-</span><span class="n">utils</span><span class="o">==</span><span class="mf">1.1.0</span> |
| 118 | +<span class="n">logutils</span><span class="o">==</span><span class="mf">0.3.3</span> |
| 119 | +<span class="n">South</span><span class="o">==</span><span class="mf">0.7.6</span> |
| 120 | +<span class="n">requests</span><span class="o">==</span><span class="mf">1.2.0</span> |
| 121 | +<span class="n">stripe</span><span class="o">==</span><span class="mf">1.9.1</span> |
| 122 | +<span class="n">dj</span><span class="o">-</span><span class="n">database</span><span class="o">-</span><span class="n">url</span><span class="o">==</span><span class="mf">0.2.1</span> |
| 123 | +<span class="n">django</span><span class="o">-</span><span class="n">oauth2</span><span class="o">-</span><span class="n">provider</span><span class="o">==</span><span class="mf">0.2.4</span> |
| 124 | +<span class="n">djangorestframework</span><span class="o">==</span><span class="mf">2.3.1</span> |
| 125 | +</pre></div> |
| 126 | + |
| 127 | + |
| 128 | +<p>Pegged dependencies with precise version numbers or Git tags are important |
| 129 | +because otherwise the latest version of a dependency will be used. While |
| 130 | +it may sound good to stay up to date, there's no telling if your application |
| 131 | +actually works with the latest versions of all dependencies. Developers should |
| 132 | +deliberately upgrade and test to make sure there were no backwards-incompatible |
| 133 | +modifications in newer dependency library versions.</p> |
96 | 134 | <h2>setup.py</h2> |
97 | 135 | <p>There is another type of dependency specification for Python libraries |
98 | 136 | known as |
|
0 commit comments