https://docs.astral.sh/uv/guides/scripts/#declaring-script-d...
You can use an alternate shebang line so you can run the script directly:
#!/usr/bin/env -S uv run --script # /// script # requires-python = ">=3.12" # dependencies = [ # "requests", # "typer-slim", # ] # /// import requests import typer # ...
reply
Uv takes the position that since it’s so fast to install dependencies and create environments, you don’t maintain a global venv.
uvx ruff file.py
Otherwise you can:
uv run —-with package file.py
https://docs.astral.sh/uv/guides/scripts/#running-a-script-w...
Or better, do the above, then create a virtual env, set the virtual env in your.bashrc and install everything into that
Better still... use uv script --init See other comments on this post
alias newpy='function _newpy() { default_deps=("rich" "requests"); uv init --script "$1" && uv add "${default_deps[@]}" --script "$1"; }; _newpy'
https://docs.astral.sh/uv/guides/scripts/#declaring-script-d...
You can use an alternate shebang line so you can run the script directly: