Self-Contained Python Scripts with uv
I saw this from Tucker’s
and Dave’s
articles.
Basically you can create a Python script, include what are the required dependencies and using uv, be able
to run the script and get the dependencies all in one go.
To add a dependency to a script you can do the following:
| |
This will include httpx as a dependency:
| |
To run this script:
| |
Also if you put the following on the first line in the script:
| |
or
| |
Now the script can be executable (chmod +x your_script.py).
Note won’t work in PowerShell but should work in Unix-like systems.
However this could work with the py launcher if you do the following:
| |