pipx icon indicating copy to clipboard operation
pipx copied to clipboard

Package List Reinstall: pipx install --packages pipx-list.json

Open halostatue opened this issue 2 years ago • 2 comments

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).

halostatue avatar Mar 14 '23 03:03 halostatue

See https://github.com/pypa/pipx/pull/874

dukecat0 avatar May 05 '23 13:05 dukecat0

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.

phanirithvij avatar May 26 '23 05:05 phanirithvij

Closing this as pipx install-all command now exists.

dukecat0 avatar Jul 11 '24 00:07 dukecat0