Ale - it doesn’t have to be terribly complicated, even if your distro defaults to not letting you use pip to install things. Let’s hypothetically say you have a simple script which happens to use rich, and your distro doesn’t package rich. Here’s the dumb script (really, this is just an example off Rich’s GitHub page):
from rich import print
print("Hello, [bold magenta]World[/bold magenta]!", ":vampire:")
Using uv to set up (this is just an example, so I’m happily picking a tool that makes this easy):
$ uv init --script myscript.py
Initialized script at `myscript.py`
$ uv add --script myscript.py rich
Updated `myscript.py`
$
uv updates the script with these two requests, so afterwards it looks like:
# /// script
# requires-python = ">=3.8"
# dependencies = [
# "rich",
# ]
# ///
from rich import print
print("Hello, [bold magenta]World[/bold magenta]!", ":vampire:")
You can now run it as:
$ uv run myscript.py
Or if you don’t want the extra typing and want to run it as an “ordinary command”, you can make it executable and add a shebang line to it:
#!/usr/bin/env -S uv run --script`
Notice this doesn’t encode any paths in the script, and you can put it anywhere. Managing the dependencies is done by asking uv to update the embedded information, you don’t need to manually edit things. For dependencies which are satisfiable by the standard library, or distro packages, there’s no need to add anything; if you do, you’ll get copies fetched (and then cached) from PyPI instead of the distro ones - so it’s your choice. There is a virtualenv involved, but (for this case - there are other operation modes besides the “simple script” one) it’s created on the fly and not retained (except for the cache of fetched packages), so you don’t have to fuss with creating it or keeping it up to date.