pipx
pipx copied to clipboard
Package List Reinstall: pipx install --packages pipx-list.json
How would this feature be useful?
I’d love to be able to use the output of pipx list --json — or some subset of same — as input to reinstall packages when moving from one machine to another. I’m less concerned with
Describe the solution you'd like
$ pipx list --include-injected --json > pipx-packages.json
$ pipx install --packages pipx-packages.json
Describe alternatives you've considered
A complex JQ script could transform the output into scriptable commands:
.venvs | to_entries[] | .key as $name | .value.metadata | [
(
.main_package | [
"pipx", "install", .package_or_url,
if .include_dependencies then "--include-deps" else null end,
if .pip_args != [] then ["--pip-args", .pip_args] else null end,
if .suffix != "" then ["--suffix", .suffix] else null end
] | select(. != null) | flatten | join(" ")
),
(
.injected_packages | map([
"pipx", "inject", $name, .package_or_url,
if .include_dependencies then "--include-deps" else null end,
if .include_apps then "--include-apps" else null end,
if .pip_args != [] then ["--pip-args", .pip_args] else null end,
if .suffix != "" then ["--suffix", .suffix] else null end
] | select(. != null) | flatten | join(" "))
)
] | flatten | join("\n")
This could be run with eval $(pipx list --include-injected --json | jq -f pipx-reinstall.jq -r).
See https://github.com/pypa/pipx/pull/874
Also https://github.com/pypa/pipx/issues/687.
P.S your jq solution is awesome for now!
I am using ansible with community.general.pipx but it has some drawbacks.
Closing this as pipx install-all command now exists.