Run scripts¶
Run an app or a script in a temporary environment with pipx run, without installing it first. pipx downloads the
package, caches the environment, and runs the app. Under the uv backend, pipx hands packages to uv tool run and
local scripts with inline metadata to uv run --script, so uv’s cache applies instead of pipx’s.
Run a specific version¶
The PACKAGE argument is a requirement specifier, so you can pin versions, ranges, or
extras:
$ pipx run mpremote==1.20.0
$ pipx run --spec esptool==4.6.2 esptool.py
$ pipx run --spec 'esptool>=4.5' esptool.py
Quote any specifier that contains >, <, or spaces.
Add extra dependencies¶
--with PKG adds packages to the temporary environment alongside the app. Repeat it to add more. For a script,
--with requires a # /// script metadata block; pipx adds the packages to its declared dependencies:
$ pipx run --with requests --with rich my-script.py
Pass arguments to Python¶
--python-args ARGS forwards arguments to the interpreter that runs the app, rather than to the app itself:
$ pipx run --python-args "-X dev" my-script.py
Run from source control¶
pipx run accepts source-control URLs directly, with the same syntax as pipx install (see
Install from source control). Using black as an example:
$ pipx run git+https://github.com/psf/black.git
$ pipx run git+https://github.com/psf/black.git@branch
Use --spec when the executable name differs from the package name or when installing from an archive URL:
$ pipx run --spec https://github.com/psf/black/archive/18.9b0.zip black
Run from a URL¶
You can run .py files hosted anywhere:
$ pipx run https://gist.githubusercontent.com/cs01/fa721a17a326e551ede048c5088f9e0f/raw/6bdfbb6e9c1132b1c38fdd2f195d4a24c540c324/pipx-demo.py
Run a script with dependencies (PEP 723)¶
A script can declare its own dependencies with inline script metadata. pipx reads the # /// script block
and installs the listed packages before running:
$ pipx run test.py pipx
1.9.0
pipx caches an environment keyed to the script’s dependency list. Changing the dependencies builds a fresh one.
When the block sets requires-python, pipx keeps the default Python if it satisfies the constraint and otherwise
looks for an interpreter that does, the same way pipx install does (see Standalone Python). An explicit
--python that fails the constraint is an error. Both backends follow this rule.
Verify it¶
$ pipx run pycowsay moo
A successful run prints the app’s own output; nothing is left installed afterward.