The screenshot arrives with no message. Just a red wall of text and, at the bottom, one line you could now recite in your sleep:
ModuleNotFoundError: No module named 'requests'
You wrote a little script. It checks whether a list of links still works. On your laptop it's lovely. You sent it to a friend because it saved you an hour, and now your friend thinks you sent them something broken.
You didn't. You sent them half of something. Here is the one idea: a Python script can carry its own shopping list of what it needs, in a comment at the top of the file, so the next send just works. By the end you'll have a script your friend can run after installing one tool, once.
What you need
A terminal (the window where you type commands: Terminal on a Mac, PowerShell or Windows Terminal on Windows), a folder to save check_links.py in, and uv, introduced below (I used 0.11.32). The friend needs only uv and a terminal.
What the friend is missing
Your script starts with a line like 'import requests'. That means "go find a toolbox called requests and let me borrow from it." requests is a popular library for fetching web pages. Python didn't come with that toolbox. You installed it at some point, probably months ago, and forgot.
A toolbox your script borrows from is called a dependency. Your laptop has yours. Your friend's doesn't, and Python's only way of saying so is that red line.
The usual answers are to write a requirements file, make a virtual environment (a private folder of installed packages), or turn the script into a standalone app. All true, all heavy, and all of them ask your friend to do chores before they see your script run.
There's a lighter option. Let the file carry its own shopping list.
The concept: the shopping list lives in a comment
Python has a standard for putting that list at the top of the script, inside comments. Python itself ignores comments, so nothing breaks. A tool that knows the format reads the comment, sees the list, and fetches what's missing before running anything. The standard is called PEP 723 — the official write-up is at peps.python.org/pep-0723 — and the comment is called inline script metadata, but think of it as a sticky note on the front of the file.
Save this as check_links.py. It's a link checker: give it web addresses, it tells you which ones answer.
# /// script # requires-python = ">=3.11" # dependencies = ["requests"] # /// import sys import requests for url in sys.argv[1:]: try: reply = requests.get(url, timeout=10) print(reply.status_code, url) except requests.RequestException as err: print("FAIL", url, type(err).__name__)
The first four lines are the sticky note. The lines between the two '# ///' markers are the part that matters. 'dependencies' is the shopping list, one quoted name per item. 'requires-python' says how new a Python the script needs.
One honest limit: the list names 'requests' with no version, so a future release could change how your script behaves. When a script matters, pin it — 'requests==2.32.3' instead of bare 'requests'.
Everything after that is an ordinary script. 'sys.argv[1:]' is just "every address typed after the filename."
Walkthrough: the friend does one thing, once
A sticky note needs somebody to read it. Plain 'python check_links.py' won't. I ran it on a machine that has no requests and got the screenshot above, word for word.
The reader is a tool called uv. Your friend installs it one time, from uv's own install guide at docs.astral.sh/uv (or search 'install uv' and follow the official Astral page). Then, in a terminal opened in the folder holding the file, they run it like this, with any web address after the filename:
uv run check_links.py https://example.com
That's the whole instruction. No environment to create, no 'pip install' to remember.
I tested it against a tiny local web server so the output was predictable. This is what the first run printed. The numbers are status codes: 200 means found, 404 means no such page:
Installed 5 packages in 4ms 200 http://127.0.0.1:8765/ 404 http://127.0.0.1:8765/nope FAIL http://127.0.0.1:1/ ConnectionError
Five packages, because requests brings four helpers with it. The second run skips the 'Installed' line, since uv keeps what it fetched.
Does the friend need Python too?
The guides say uv can fetch Python for you. I wanted to watch it happen, so I made the situation on purpose.
I put a copy of uv alone in an empty folder, pointed my shell's search path — the list of folders it looks through to find a command — at only that folder, and confirmed the shell could find no Python at all. Then I ran the same command. On uv 0.11.32, the first thing it printed was:
Downloading cpython-3.14.6-linux-x86_64-gnu (download) (34.3MiB)
After that it installed the five packages and the script ran. So yes: on a machine with no Python, 'uv run' went and got one. It picked 3.14.6, which satisfied my '>=3.11'. Yours may pick a different one, which is why 'requires-python' is worth writing down honestly.
One limit: it was a Linux box, so I haven't watched it happen on Windows or a Mac. The promise I'll make your friend is the one I saw: install uv once, and the Python part takes care of itself. The first run is slower because of that download. After it, runs are quick.
Show the code
<style>
pre{background:#1e1e22;color:#e6e6e6;border-radius:8px;padding:10px;font:13px/1.5 ui-monospace,Menlo,Consolas,monospace;white-space:pre-wrap;word-break:break-word;margin:8px 0}
#file{background:#f6f6f8;color:#1d1d1f;border:1px solid #ddd}
#file .note{background:#fff3c4;display:block;border-radius:4px}
#file .note.read{background:#c8e6c9}
.row{display:flex;flex-wrap:wrap;gap:8px;margin:8px 0;align-items:center}
.row button,select{min-height:40px;font:inherit;font-size:15px;padding:6px 12px;border:1px solid #999;border-radius:8px;background:#f4f4f6;cursor:pointer}
.row label{font-size:15px}
#say{font-size:15px;font-weight:600}
</style>
<label for="deps" style="font-size:15px">Shopping list in the note:</label>
<div class="row"><select id="deps"><option value="requests">dependencies = ["requests"]</option><option value="json">dependencies = ["json"]</option></select></div>
<pre id="file"><span class="note" id="note"></span>import sys
import requests
...</pre>
<p style="font-size:15px;margin:0">Run it with:</p>
<div class="row">
<button id="py">python check_links.py ...</button>
<button id="uv">uv run check_links.py ...</button>
</div>
<pre id="out" aria-live="polite">$</pre>
<p id="say"></p>
<script>
var uvRuns = 0;
function drawNote(read) {
var d = document.getElementById('deps').value, n = document.getElementById('note');
n.textContent = '# /// script\n# requires-python = ">=3.11"\n# dependencies = ["' + d + '"]\n# ///\n';
n.className = 'note' + (read ? ' read' : '');
}
document.getElementById('deps').onchange = function () { uvRuns = 0; drawNote(false); document.getElementById('out').textContent = '$'; document.getElementById('say').textContent = ''; };
document.getElementById('py').onclick = function () {
drawNote(false);
document.getElementById('out').textContent = '$ python check_links.py ...\n...\nModuleNotFoundError: No module named \'requests\'';
document.getElementById('say').textContent = 'Python treats the note as a comment and skips it, so nothing fetched requests.';
};
document.getElementById('uv').onclick = function () {
drawNote(true);
var out = '$ uv run check_links.py ...\n', say;
if (document.getElementById('deps').value === 'json') {
out += '× No solution found when resolving script dependencies:\n╰─▶ Because json was not found in the package registry and you require json,\n we can conclude that your requirements are unsatisfiable.';
say = 'uv read the note and went shopping for json, which ships with Python. List only what you had to install.';
} else {
uvRuns++;
if (uvRuns === 1) out += 'Installed 5 packages in 4ms\n';
out += '200 http://127.0.0.1:8765/\n404 http://127.0.0.1:8765/nope\nFAIL http://127.0.0.1:1/ ConnectionError';
say = uvRuns === 1 ? 'uv read the note (green), fetched requests and its four helpers, then ran the script. Click again for a second run.' : 'Second run: no Installed line, because uv kept what it fetched.';
}
document.getElementById('out').textContent = out;
document.getElementById('say').textContent = say;
};
drawNote(false);
</script>Where it goes wrong: the note wins, and it wins alone
Suppose you, or your friend, keep this script inside a folder that already holds a uv project — meaning a folder with a 'pyproject.toml' next to it. I built one to see what happens. I gave the project a dependency on 'rich', then dropped in two scripts.
A script with a sticky note got only what its own note listed. When that script imported 'rich', which the project had but the note didn't, it crashed with 'No module named rich'. A script with no sticky note got only the project's list, and a plain 'import requests' crashed there instead.
I'd expected the note to be ignored next to a project, with the project's dependencies taking over. It was the other way round, and I'm glad I checked before telling you the first thing. So the rule is simple: if a script has a note, the note is its whole world. Put every dependency it uses on the note, even when a project is sitting right beside it.
Where it goes wrong: listing what Python already ships
Don't list things Python already ships with. 'json', 'os', 'sys', 'csv' and friends come with Python. They are not toolboxes to fetch. It's an easy mistake, because the shopping list feels like it should mirror every import line. It shouldn't. I tried it, with 'dependencies = ["json"]', and uv stopped before running anything:
× No solution found when resolving script dependencies: ╰─▶ Because json was not found in the package registry and you require json, we can conclude that your requirements are unsatisfiable.
Translation: you asked the store for something the store doesn't sell, because it was already in the house. A quick test for any import: if you had to install it on your own laptop once, it goes on the list. If it was just there, it doesn't.
The one file you send
Send the file, and send this along with it:
Install uv once (docs.astral.sh/uv). Then, in a terminal, run: uv run check_links.py https://your-site.com
If you want them to skip typing 'uv run' on Mac or Linux, there's an extra first line you can add, and I ran this too:
#!/usr/bin/env -S uv run --script
Put that above the sticky note, then mark the file runnable with 'chmod +x check_links.py' ('chmod +x' is the one-time command that tells the system a file is a program it may run). Now './check_links.py' works on its own. On a machine without uv, it tells you so instead of hiding the problem:
/usr/bin/env: 'uv': No such file or directory
That's a better first error than a missing module, because it points at the one thing to install rather than at your code.
Recap
- A script can carry its own dependencies in a comment (PEP 723 inline script metadata).
- 'uv run' reads the note, fetches what's missing, and on my Linux test even fetched Python when none was installed.
- The note is the script's whole world, even next to a uv project.
- List only what you had to install, never what ships with Python.
Next, open the last thing you sent someone that needed a library. Add the four-line note: 'dependencies' listing only the things you had to install yourself, and 'requires-python' set to ">=3.11" unless you know you need something newer. Then test it the way I did: go to a folder where nothing is installed and run 'uv run yourscript.py'. If it works there, it will work for them.