<?xml version="1.0" encoding="utf-8"?> 
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
 <title type="text">Will Lachance&#39;s Log: Posts tagged &#39;python&#39;</title>
 <link rel="self" href="https://wrla.ch/feeds/python.atom.xml" />
 <link href="https://wrla.ch/tags/python.html" />
 <id>urn:https-wrla-ch:-tags-python-html</id>
 <updated>2026-02-26T17:17:43Z</updated>

 <entry>
  <title type="text">`uv run` isn&#39;t always what you want</title>
  <link rel="alternate" href="https://wrla.ch/log/2026/02/uv-run-isn-t-always-what-you-want/?utm_source=python&amp;utm_medium=Atom" />
  <id>urn:https-wrla-ch:-log-2026-02-uv-run-isn-t-always-what-you-want</id>
  <published>2026-02-26T17:17:43Z</published>
  <updated>2026-02-26T17:17:43Z</updated>
  <author>
   <name>Will Lachance</name></author>
  <content type="html">
&lt;p&gt;Like many others, I&#39;ve joined the cult of &lt;a href=&#34;https://docs.astral.sh/uv&#34;&gt;uv&lt;/a&gt;. One superpower is that you no longer really need to think of activating a virtual environment in a project managed with this tool, &lt;code&gt;uv run path/to/script.py&lt;/code&gt; will do the right thing.
You don&#39;t have to think about whether the virtual environment exists or is up to date, uv takes care of that under the hood and then runs your script inside the environment.&lt;/p&gt;
&lt;p&gt;This is &lt;em&gt;great&lt;/em&gt; for local development but isn&#39;t generally what you want if:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You&#39;re running a service inside a docker container and the virtual environment is already created (you ideally shouldn&#39;t even have uv installed)&lt;/li&gt;
&lt;li&gt;You&#39;ve created a standalone tool with a virtualenv and just want to run it by itself (and not develop it).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For these cases, generally either set your path to include the virtual environment created by uv (&lt;code&gt;/prefix/.venv/bin&lt;/code&gt;) or just run the script directly (&lt;code&gt;/prefix/.venv/bin/script.py&lt;/code&gt;). &lt;code&gt;uv run&lt;/code&gt; has startup overhead and inside a docker container, you also don&#39;t &lt;em&gt;want&lt;/em&gt; to dynamically download a bunch of new things: you just want to use
what you already created.&lt;/p&gt;
&lt;p&gt;tl;dr: &lt;code&gt;uv run&lt;/code&gt; is for development. Just execute the actual script in production.&lt;/p&gt;
</content></entry>
</feed>