I wish an easy cross-platform PEX or shiv [1] were a thing.
Binary dependencies are the biggest reason I prefer the new inline script metadata spec (
https://packaging.python.org/en/latest/specifications/inline...) and `pipx run`.
Luckily, they're pretty great.
They have changed how I write Python scripts.
The way inline script metadata works is that your script declares arbitrary dependencies in a structured top comment, and a compliant script runner must provide them.
Here is an example from a real script:
#! /usr/bin/env -S pipx run
# /// script
# dependencies = [
# "click==8.*",
# "Jinja2==3.*",
# "tomli==2.*",
# ]
# requires-python = ">=3.8"
# ///
pipx implements the spec with cached per-script virtual environments.
It will download the dependencies, create a venv for your script, and install the dependencies in the venv the first time you invoke the script.
The idea isn't new: you could do more or less the same with
https://github.com/PyAr/fades (2014) and
https://github.com/jaraco/pip-run (2015).
However, I only adopted it after I saw
https://peps.python.org/pep-0722/, which PEP 723 replaced and became the current standard.
It is nice to have it standardized and part of pipx.
For really arbitrary hosts with no guarantee of recent pipx,
there is https://pip.wtf and my venv version https://github.com/dbohdan/pip-wtenv.
Personally, I'd go with `pipx run` instead whenever possible.
[1] I recommend shiv over PEX for pure-Python dependencies because shiv builds faster. Have a look at https://shiv.readthedocs.io/en/stable/history.html.