From b845df73a74afc94e1df3dc87b6101aef3350c4d Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sun, 24 Dec 2023 10:26:50 +0000 Subject: [PATCH] Run commands using their real paths Fixes #1164 --- CHANGELOG.md | 1 + src/pipx/util.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50037843e3..a45ec8c4c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## dev +- Fix "No pyvenv.cfg file" error when using Microsoft Store Python (#1164) - Add `--quiet` and `--verbose` options for the `pipx` subcommands - [docs] Add Scoop installation instructions - Add ability to install multiple packages at once diff --git a/src/pipx/util.py b/src/pipx/util.py index b2c340818f..24ef45b548 100644 --- a/src/pipx/util.py +++ b/src/pipx/util.py @@ -171,6 +171,17 @@ def run_subprocess( logger.info(f"running {log_cmd_str}") # windows cannot take Path objects, only strings cmd_str_list = [str(c) for c in cmd] + # Make sure to call the binary using its real path. This matters especially + # on Windows when using the packaged app (Microsoft Store) version of + # Python, which uses path redirection for sandboxing. If the path to the + # executable is redirected, the executable can get confused as to which + # directory it's being run from, leading to problems. + # See https://github.com/pypa/pipx/issues/1164 + # Conversely, if the binary is a symlink, then we should NOT use the real + # path, as Python expects to receive the symlink in argv[0] so that it can + # locate the venv. + if not os.path.islink(cmd_str_list[0]): + cmd_str_list[0] = os.path.realpath(cmd_str_list[0]) completed_process = subprocess.run( cmd_str_list, env=env,