<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vitor Ramalho on Medium]]></title>
        <description><![CDATA[Stories by Vitor Ramalho on Medium]]></description>
        <link>https://medium.com/@ramalhodevitor?source=rss-13891f79ac39------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7vpf0s8EUFwVGBsS</url>
            <title>Stories by Vitor Ramalho on Medium</title>
            <link>https://medium.com/@ramalhodevitor?source=rss-13891f79ac39------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 11:18:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ramalhodevitor/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Abandon requirements.txt for managing dependencies in Python immediately]]></title>
            <link>https://medium.com/@ramalhodevitor/abandon-requirements-txt-for-managing-dependencies-in-python-immediately-50b1c45b824a?source=rss-13891f79ac39------2</link>
            <guid isPermaLink="false">https://medium.com/p/50b1c45b824a</guid>
            <category><![CDATA[pip]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[dependencies]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Vitor Ramalho]]></dc:creator>
            <pubDate>Thu, 06 Jan 2022 23:04:35 GMT</pubDate>
            <atom:updated>2022-01-06T23:04:35.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jqwf3sUzzfpdVpYv3DwOxw.png" /><figcaption>requirements.txt in its natural habitat</figcaption></figure><p><strong>This quick article is meant for beginner to intermediate users of Python.</strong></p><p>It’s funny how things go, right? A few years back, when I first found out about requirements.txt and virtual environments for Python, my mind was blown. I started feeling myself a senior just because I could finally separate/share my project&#39;s dependencies and stop having a messy global Python installation. Well, I didn’t know that was all about it.</p><p>The requirements.txt file is a very useful way of managing your dependencies, but after a while when you have multiple dependencies that have their own sub-dependencies, you start getting lost in their relationships and you simply know that’s not enough anymore.</p><p><em>I don’t get it!</em></p><h4>Example</h4><p>Let’s go over a quick example to explain the main problems of using it.</p><p>You install dependency <strong>F</strong>, which happens to have <strong>G</strong> as a sub-dependency. After a while, all you see in requirements.txt is <strong>A, B, C, D, E, F, G, H </strong>as your dependencies.</p><p>You don’t know which dependencies were installed directly or indirectly, so updating or even removing <strong>F </strong>now becomes a problem, as you will have to search to know that <strong>G</strong> was installed as a sub-dependency. And even if you search, can you remove <strong>G, </strong>or is that a sub-dependency for some other package?</p><p>You end up leaving the stale dependency there and piling up trash or spending a lot of time doing a complete search and removing everything that’s unused.</p><p>And that’s not the only problem with it. As you use <em>pip freeze </em>to translate your installed dependencies in a requirements.txt file, if you’re not careful enough and install a package just for test purposes, that can also end up in your project’s dependencies for good.</p><p><em>Well, I’m convinced, what do I do?</em></p><h4>Solution</h4><p>As shining lights for that problem, a lot of smart people came up with better ways to manage your dependencies in Python. To mention just a few, we have <a href="https://github.com/jazzband/pip-tools">pip-tools</a> and <a href="https://python-poetry.org/">poetry</a>.</p><p>In this article, we will develop how to use pip-tools to give you a solid example of how to manage your dependencies from the start of your project. Let’s assume we have a project in which we will have to use <strong>Django </strong>and P<strong>andas</strong>.</p><ol><li><strong>Install pip-tools</strong></li></ol><p>First of all, you need to install pip-tools in every virtualenv that you’ll work, but it will as simple as using:</p><blockquote>python3 -m venv venv</blockquote><blockquote>source venv/bin/activate</blockquote><blockquote>pip install pip-tools</blockquote><p>2. <strong>Create requirements.in file</strong></p><p>Now, we’ll need to create a requirement.in file and include only the direct dependencies for our project. This will be your new go-to requirements file from now on. Every time you want to update or include a dependency, you’ll have to come here and include it. And it will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IARE6rs-VAT33pEFp6iq4A.png" /></figure><p>Can you see how it differs from the old .txt file? In this one, we only include the direct dependencies. And you can choose to include version limitations or not, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*BmuspeRnCO0p1hbDSV7CVQ.png" /></figure><p><em>But how does that help us?</em></p><p><strong>3. Compile your requirements</strong></p><p>The main difference here is that this is the recipe for generating your requirements.txt from now on. After you finish creating it, you’ll run to finally compile your requirements:</p><blockquote>pip-compile ./requirements.in</blockquote><p>This will generate a requirements.txt in the same folder you generated your .in file. But you’ll see a big difference between the two of them. The requirements.txt now controls exactly if a certain package is a sub-dependency of others by appending that information right underneath them, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S86IsVIAVCT1KDOiCGzOKw.png" /></figure><p>And just like that, you eliminated all the problems discussed before. As you have all the information you need to manage your packages right under your nose. Notice that Django is respecting the constraint of “less than version 4” that we imposed in the requirements.in file presented.</p><p><strong>4. Extra functions</strong></p><p>Apart from that, pip-tools offer other convenience functions that you may explore to make your flow even easier. A few of those are presented below.</p><p><strong><em>Upgrade Packages</em></strong></p><p>To upgrade packages, use the following command (example with Django):</p><blockquote>pip-compile --upgrade-package django</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XVcINlLC3qgAVHMsNiDKJQ.png" /></figure><p>This will automatically update your requirements.txt file including those changes. Just remember to remove the constraint “less than version 4” to allow it.</p><p><strong><em>Sync Packages</em></strong></p><p>In order to sync your virtualenv with your current requirements.txt file, you can simply run the following command:</p><blockquote>pip-sync</blockquote><p>This will install, upgrade or uninstall any packages not contained on your requirements.txt file. Make it easier for your to explore a package and get rid of it really fast.</p><p>For more details about pip-tools, refer to its <a href="https://github.com/jazzband/pip-tools">documentation</a>.</p><p>I hope this article is helpful for all of you starting to explore this path, as I tried to include all the necessary knowledge to accomplish it. I apologize for any mistakes included and I appreciate all the discussions that may help to improve this content. Reach out in case you have questions or want to discuss similar experiences with me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50b1c45b824a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>