Skip to content

Commit c85b694

Browse files
committed
fix: install to the user home when using pipx as sudo
1 parent f55ff60 commit c85b694

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/utils/setup/setupPipPack.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { hasDnf } from "../env/hasDnf"
1515
import { setupDnfPack } from "./setupDnfPack"
1616
import { isUbuntu } from "../env/isUbuntu"
1717
import { setupAptPack } from "./setupAptPack"
18+
import { untildifyUser } from "untildify-user"
1819

1920
export type SetupPipPackOptions = {
2021
/** Whether to use pipx instead of pip */
@@ -56,8 +57,17 @@ export async function setupPipPackWithPython(
5657
const upgradeFlag = upgrade ? (isPipx ? ["upgrade"] : ["install", "--upgrade"]) : ["install"]
5758
const userFlag = !isPipx && user ? ["--user"] : []
5859

60+
const env = process.env
61+
62+
if (isPipx && user) {
63+
// install to user home
64+
env.PIPX_HOME = untildifyUser("~/.local/pipx")
65+
env.PIPX_BIN_DIR = untildifyUser("~/.local/bin")
66+
}
67+
5968
execaSync(givenPython, ["-m", pip, ...upgradeFlag, ...userFlag, nameAndVersion], {
6069
stdio: "inherit",
70+
env,
6171
})
6272
} catch (err) {
6373
info(`Failed to install ${name} via ${pip}: ${err}.`)

0 commit comments

Comments
 (0)