From c85b694b1c3fe1e420dd386c979485f78132d4c9 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 22 Jan 2024 02:38:47 -0800 Subject: [PATCH] fix: install to the user home when using pipx as sudo --- src/utils/setup/setupPipPack.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/utils/setup/setupPipPack.ts b/src/utils/setup/setupPipPack.ts index ee60190b..be880da5 100644 --- a/src/utils/setup/setupPipPack.ts +++ b/src/utils/setup/setupPipPack.ts @@ -15,6 +15,7 @@ import { hasDnf } from "../env/hasDnf" import { setupDnfPack } from "./setupDnfPack" import { isUbuntu } from "../env/isUbuntu" import { setupAptPack } from "./setupAptPack" +import { untildifyUser } from "untildify-user" export type SetupPipPackOptions = { /** Whether to use pipx instead of pip */ @@ -56,8 +57,17 @@ export async function setupPipPackWithPython( const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"] const userFlag = !isPipx && user ? ["--user"] : [] + const env = process.env + + if (isPipx && user) { + // install to user home + env.PIPX_HOME = untildifyUser("~/.local/pipx") + env.PIPX_BIN_DIR = untildifyUser("~/.local/bin") + } + execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], { stdio: "inherit", + env, }) } catch (err) { info(`Failed to install ${name} via ${pip}: ${err}.`)