Skip to content

Commit 81c2fa5

Browse files
authored
Pass real paths when running subprocesses (#1168)
1 parent 31a8da5 commit 81c2fa5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## dev
22

3+
- Delete directories directly instead of spawning rmdir on Windows
4+
- Fix "Failed to delete" error when using Microsoft Store Python
5+
- Fix "No pyvenv.cfg file" error when using Microsoft Store Python (#1164)
36
- Add `--quiet` and `--verbose` options for the `pipx` subcommands
47
- [docs] Add Scoop installation instructions
58
- Add ability to install multiple packages at once

src/pipx/util.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ def rmdir(path: Path, safe_rm: bool = True) -> None:
5454

5555
logger.info(f"removing directory {path}")
5656
try:
57-
if WINDOWS:
58-
os.system(f'rmdir /S /Q "{str(path)}"')
59-
else:
60-
shutil.rmtree(path)
57+
shutil.rmtree(path)
6158
except FileNotFoundError:
6259
pass
6360

@@ -171,6 +168,14 @@ def run_subprocess(
171168
logger.info(f"running {log_cmd_str}")
172169
# windows cannot take Path objects, only strings
173170
cmd_str_list = [str(c) for c in cmd]
171+
# Make sure to call the binary using its real path. This matters especially on Windows when using the packaged app
172+
# (Microsoft Store) version of Python, which uses path redirection for sandboxing. If the path to the executable is
173+
# redirected, the executable can get confused as to which directory it's being run from, leading to problems.
174+
# See https://github.com/pypa/pipx/issues/1164
175+
# Conversely, if the binary is a symlink, then we should NOT use the real path, as Python expects to receive the
176+
# symlink in argv[0] so that it can locate the venv.
177+
if not os.path.islink(cmd_str_list[0]):
178+
cmd_str_list[0] = os.path.realpath(cmd_str_list[0])
174179
completed_process = subprocess.run(
175180
cmd_str_list,
176181
env=env,

0 commit comments

Comments
 (0)