How to install and use uv: init a project, add a package, run a script
Install uv from the official steps, create a project, add one package, and run a script with uv run.
To manage a Python project with uv on your machine, finish four jobs: install from the official channel, uv init, uv add one package, then uv run a script.
Follow docs.astral.sh/uv/ instead of guessing package names. The queries are how to install uv, uv init, and run a script with uv run. The installer lives at astral.sh/uv.
Install the official binary for your OS
macOS and Linux
Official script: curl -LsSf https://astral.sh/uv/install.sh | sh. Or brew install uv. Open a new terminal and run uv --version.
Windows
PowerShell: irm https://astral.sh/uv/install.ps1 | iex. Start a new session and confirm uv is on PATH.
| Step | Command | Watch for |
|---|---|---|
| Install | uv --version | The current shell must see the official binary |
| Project | uv init myproject | pyproject.toml should appear |
| Dependency | uv add httpx | Use the PyPI name; the lockfile updates |
| Script | uv run python hello.py | Uses the project env; no manual activate |
Install, init, add a package, run a script
- 01Install and confirm the version
Follow docs.astral.sh/uv/getting-started/installation/ for the script or Homebrew.
uv --versionshould print a version. If the command is missing, open a new terminal and check PATH. - 02Create a project
In the parent directory run
uv init myproject, thencd myproject. You should seepyproject.toml. An empty folder can take a bareuv init. - 03Add one package
Run
uv add httpxas an example. uv resolves deps, writes the lockfile, and prepares the environment. On failure, check the package name and the network; do not hand-edit a half-written lockfile. - 04Write and run a script
Create
hello.pythat uses the new package, thenuv run python hello.py. To pin an interpreter first, runuv python install.
curl -LsSf https://astral.sh/uv/install.sh | sh
uv --version
uv init myproject
cd myproject
uv add httpx
# After you write hello.py:
uv run python hello.py- Is the official install script required?
- No. The docs also list Homebrew, WinGet, and other channels. Pick one and verify with uv --version. Do not stack several copies that fight over PATH.
- Do I still create a venv myself?
- Not for daily use. uv add and uv run use the project environment. Add .venv to .gitignore; do not commit it.
- How is uv run different from python?
- A system python may not see project dependencies. uv run selects the project interpreter and installed packages.
- Does install replace a shared diagram?
- No. This is a Python toolchain. When the meeting is the same diagram, open sitdraw.
Get uv on PATH first
Until uv --version works, do not treat a failed init as a template bug. Most failures are a shell that never loaded the PATH the installer changed.