Skip to content
Tech News
← Back to articles

uv Running a Script with Dependencies

read original get Amazon Echo Show → more articles

A Python script is a file intended for standalone execution, e.g., with python <script>.py . Using uv to execute scripts ensures that script dependencies are managed without manually managing environments.

Note If you are not familiar with Python environments: every Python installation has an environment that packages can be installed in. Typically, creating virtual environments is recommended to isolate packages required by each script. uv automatically manages virtual environments for you and prefers a declarative approach to dependencies.

If your script has no dependencies, you can execute it with uv run :

example.py print ( "Hello world" )

$ uv run example.py Hello world

Similarly, if your script depends on a module in the standard library, there's nothing more to do:

example.py import os print ( os . path . expanduser ( "~" ))

$ uv run example.py /Users/astral

Arguments may be provided to the script:

example.py import sys print ( " " . join ( sys . argv [ 1 :]))

... continue reading