Skip to content

Commit

Permalink
Run commands using their real paths
Browse files Browse the repository at this point in the history
Fixes #1164
  • Loading branch information
dechamps committed Dec 25, 2023
1 parent 1a3e6ad commit 825b5ef
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pipx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 825b5ef

Please sign in to comment.