mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
[docs] Add shebang section for scripts (#11553)
<!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Documentation only. Adds a section in scripts.md about running uv scripts with a shebang line ## Test Plan n/a --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
e58cc39238
commit
d9243cee7e
1 changed files with 33 additions and 0 deletions
|
@ -217,6 +217,39 @@ print(Point)
|
|||
is not installed — see the documentation on [Python versions](../concepts/python-versions.md) for
|
||||
more details.
|
||||
|
||||
## Using a shebang to create an executable file
|
||||
|
||||
A shebang can be added to make a script executable without using `uv run` — this makes it easy to
|
||||
run scripts that are on your `PATH` or in the current folder.
|
||||
|
||||
For example, create a file called `greet` with the following contents
|
||||
|
||||
```python title="greet"
|
||||
#!/usr/bin/env -S uv run --script
|
||||
|
||||
print("Hello, world!")
|
||||
```
|
||||
|
||||
Ensure that your script is executable, e.g., with `chmod +x greet`, then run the script:
|
||||
|
||||
```console
|
||||
$ ./greet
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
Declaration of dependencies is also supported in this context, for example:
|
||||
|
||||
```python title="example"
|
||||
#!/usr/bin/env -S uv run --script
|
||||
# /// script
|
||||
# requires-python = ">=3.12"
|
||||
# dependencies = ["httpx"]
|
||||
# ///
|
||||
import httpx
|
||||
|
||||
print(httpx.get("https://example.com"))
|
||||
```
|
||||
|
||||
## Using alternative package indexes
|
||||
|
||||
If you wish to use an alternative [package index](../configuration/indexes.md) to resolve
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue