<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Hew Hahn - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Hew Hahn - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Fri, 08 May 2026 14:34:25 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/hew/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Manage Python Packages with uv ]]>
                </title>
                <description>
                    <![CDATA[ Python package managers let you install and manage dependencies—like NumPy, pandas, and so on—right from your terminal. In this article, you will learn how to use uv—an extremely fast Python package manager. Prerequisites To get the most out of this ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-manage-python-packages-with-uv/</link>
                <guid isPermaLink="false">69089c3b30ea29f0efb3f4fd</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ package ]]>
                    </category>
                
                    <category>
                        <![CDATA[ terminal ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Hew Hahn ]]>
                </dc:creator>
                <pubDate>Mon, 03 Nov 2025 12:12:43 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1762169941014/9e66858d-3ba4-434e-a9f1-84d42a316192.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Python package managers let you install and manage dependencies—like NumPy, pandas, and so on—right from your terminal.</p>
<p>In this article, you will learn how to use <code>uv</code>—an extremely fast Python package manager.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To get the most out of this tutorial, you will need to:</p>
<ul>
<li><p>Know how to execute commands in your terminal,</p>
</li>
<li><p>Be familiar with basic Python development/scripting.</p>
</li>
</ul>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-why-should-you-use-uv">Why Should You Use uv?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-install-uv">How to Install uv</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-set-up-a-project-with-uv">How to Set up a Project with uv</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-commonly-used-uv-commands">Commonly Used uv Commands</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-how-to-add-a-dependency">How to Add a Dependency</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-remove-a-dependency">How to Remove a Dependency</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-run-python-code">How to Run Python Code</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-move-your-project">How to Move Your Project</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-add-and-run-tools">How to Add and Run Tools</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-run-tools-without-adding-them-to-your-project">How to Run Tools Without Adding Them to Your Project</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-manage-multiple-python-versions">How to Manage Multiple Python Versions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-migrate-from-pip-to-uv">How to Migrate from pip to uv</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-why-should-you-use-uv">Why Should You Use uv?</h2>
<p><code>uv</code> is a free and open-source Python project management tool. Written in Rust, <code>uv</code> is fast and easy-to-use. It has become a standard package manager for modern Python development. You can also use it to manage your virtual environments, making it a good alternative for <code>pip</code> and <code>venv</code>.</p>
<p><a target="_blank" href="https://docs.astral.sh/uv/">Speed tests</a> have shown that <code>uv</code> is faster than other popular package managers when it comes to installing dependencies.</p>
<h2 id="heading-how-to-install-uv">How to Install uv</h2>
<p>To install <code>uv</code>, simply execute the following command in your terminal:</p>
<p>For Linux/macOS:</p>
<pre><code class="lang-bash">curl -LsSf https://astral.sh/uv/install.sh | sh
</code></pre>
<p>For Windows:</p>
<pre><code class="lang-powershell">powershell <span class="hljs-literal">-ExecutionPolicy</span> ByPass <span class="hljs-literal">-c</span> <span class="hljs-string">"irm https://astral.sh/uv/install.ps1 | iex"</span>
</code></pre>
<h2 id="heading-how-to-set-up-a-project-with-uv">How to Set up a Project with uv</h2>
<p>To start a new project with <code>uv</code>, run the following command:</p>
<pre><code class="lang-bash">uv init freecodecamp-project
</code></pre>
<p>This creates the folder <code>/freecodecamp-project</code> in your working directory with the following structure:</p>
<pre><code class="lang-bash">├── .gitignore <span class="hljs-comment"># hidden text file that lists files to be ignored by git</span>
├── .python-version <span class="hljs-comment"># hidden text file that keeps record of your Python's version number</span>
├── README.md
├── main.py
└── pyproject.toml
</code></pre>
<p><code>README.md</code> is a markdown file, which you can use to communicate information about your project (just as a repository README file on GitHub). <code>pyproject.toml</code> is the configuration file for your project. You can edit it to change your project’s name, version and description. It also keeps track of dependencies you add to project. Last but not least, <code>main.py</code> is where you put your Python code.</p>
<h2 id="heading-commonly-used-uv-commands">Commonly Used uv Commands</h2>
<p>Before you can run any <code>uv</code> commands, move your terminal into your project folder:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> freecodecamp-project
</code></pre>
<h3 id="heading-how-to-add-a-dependency">How to Add a Dependency</h3>
<p>To add a dependency (for example, NumPy), run:</p>
<pre><code class="lang-bash">uv add numpy
<span class="hljs-comment"># or if you need a specific version</span>
uv add <span class="hljs-string">'numpy==2.3.0'</span>
</code></pre>
<p>This automatically adds a virtual environment and a <code>.lock</code> file with a new entry:</p>
<pre><code class="lang-bash">├── .venv <span class="hljs-comment"># hidden folder inside of which your required packages will be installed</span>
└── uv.lock
</code></pre>
<p>The <code>.lock</code> file keeps record of the exact versions of your dependencies and their required packages. You should never modify it directly.</p>
<h3 id="heading-how-to-remove-a-dependency">How to Remove a Dependency</h3>
<p>To remove a dependency, run:</p>
<pre><code class="lang-bash">uv remove numpy
</code></pre>
<p>This will also remove the corresponding entry from the <code>.lock</code> file.</p>
<h3 id="heading-how-to-run-python-code">How to Run Python Code</h3>
<p>To run your Python script, execute:</p>
<pre><code class="lang-bash">uv run main.py
</code></pre>
<p>This will run the code inside the created virtual environment with the installed dependencies in one step! That is, you don’t need to explicitly activate the virtual environment and then run your code.</p>
<h3 id="heading-how-to-move-your-project">How to Move Your Project</h3>
<p>Sometimes you may want to move your project to another machine. Maybe you want to share it with colleagues, or set it up on a production server. Getting to run your code on another machine has never been easier than with <code>uv</code>. You can simply copy your project folder to the destination environment and run the following command in the destination terminal:</p>
<pre><code class="lang-bash">uv sync --locked
</code></pre>
<p>This installs the exact versions of your project dependencies!</p>
<h3 id="heading-how-to-add-and-run-tools">How to Add and Run Tools</h3>
<p>Sometimes you may need tools like <code>ruff</code>, a Python linter (code formatter), which you can add just like any other dependency to your project:</p>
<pre><code class="lang-bash">uv add ruff
</code></pre>
<p>To run an installed tool, execute:</p>
<pre><code class="lang-bash">uv run ruff check
</code></pre>
<h3 id="heading-how-to-run-tools-without-adding-them-to-your-project">How to Run Tools Without Adding Them to Your Project</h3>
<p>Sometimes you may not want to add tools to your dependencies. For example, because you just want to make one-off checks. <code>uv</code> has got you covered with <code>tool run</code>. Simply run:</p>
<pre><code class="lang-bash">uv tool run ruff check
<span class="hljs-comment"># or equivalently </span>
uvx ruff check
</code></pre>
<p>This will run the tool in an isolated environment independent.</p>
<h3 id="heading-how-to-manage-multiple-python-versions">How to Manage Multiple Python Versions</h3>
<p>If your system has Python installed, <code>uv</code> will use it. Otherwise, it will automatically install the latest Python version when you execute Python code or create a virtual environment with <code>uv</code>. However, you can also use it to manage multiple Python versions:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># install the latest Python version</span>
uv python install
<span class="hljs-comment"># install multiple Python versions</span>
uv python install 3.11 3.12
<span class="hljs-comment"># list all installed Python versions</span>
uv python list
<span class="hljs-comment"># set the version to be used in the current project (.python-version)</span>
uv python pin 3.11
</code></pre>
<h3 id="heading-how-to-migrate-from-pip-to-uv">How to Migrate from pip to uv</h3>
<p><code>uv</code> works as drop-in replacement for <code>pip</code>, meaning that you can use common <code>pip</code> commands with <code>uv</code>. Let’s say you received a <code>requirements.txt</code> file. To install the listed dependencies, you can run:</p>
<pre><code class="lang-bash">uv pip install -r requirements.txt
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>You just learned how to use <code>uv</code>! Before <code>uv</code>, managing dependencies, virtual environments and Python versions had been notoriously cumbersome. As an ML engineer at <a target="_blank" href="https://mljobs.io">MLjobs.io</a>, I can safely say that <code>uv</code> has been a game changer. Check out <code>uv</code>'s <a target="_blank" href="https://docs.astral.sh/uv/">documentation</a> to learn more.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
