---
title: "💭 Lazy self-installing Python scripts with uv"
description: "!https://treyhunner.com/2024/12/lazy-self-installing-python-scripts-with-uv/"
date: 2024-12-24
published: true
tags:
  - python
  - uv
  - thought
template: link
---


<div class="embed-card embed-card-external">
  <a href="https://treyhunner.com/2024/12/lazy-self-installing-python-scripts-with-uv/" class="embed-card-link" target="_blank" rel="noopener noreferrer">
    <div class="embed-card-image">
      <img src="https://www.gravatar.com/avatar/93a988bd85040f58f8417dc4be78c7de?s=500" alt="Lazy self-installing Python scripts with uv — I frequently find myself writing my own short command-line scripts in Python that help me with day-to-day tasks. It’s so easy to throw together …" loading="lazy">
    </div>
    <div class="embed-card-content">
      <div class="embed-card-title">Lazy self-installing Python scripts with uv</div>
      <div class="embed-card-description">I frequently find myself writing my own short command-line scripts in Python that help me with day-to-day tasks. It’s so easy to throw together …</div>
      <div class="embed-card-meta">treyhunner.com</div>
    </div>
  </a>
</div>


I really like Trey's steps to making an executable python script with uv

his old process seems to be the same with a new shebang

> 1. Add an appropriate shebang line above the first line in the file (e.g. #!/usr/bin/env python3)
> 2. Aet an executable bit on the file (chmod a+x my_script.py)
> 3. Place the script in a directory that’s in my shell’s PATH variable (e.g. cp my_script.py ~/bin/my_script)


And here is the new format the the shebang followed by the metadata comment block defined in PEP 723.

``` bash
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "ffmpeg-normalize",
# ]
# ///
```


!!! note

    This post is a <a href="/thoughts/" class="wikilink" data-title="Thoughts" data-description="These are generally my thoughts on a web page or some sort of url, except a rare few don&#39;t have a link. These are dual published off of my..." data-date="2024-04-01">thought</a>. It's a short note that I make
    about someone else's content online <a href="/tags/thoughts/" class="hashtag-tag" data-tag="thoughts" data-count=2 data-reading-time=3 data-reading-time-text="3 minutes">#thoughts</a>
