Skip to content

Commit 488c981

Browse files
committed
fix: use an absolute path to pip3 and python on windows
1 parent 8daf638 commit 488c981

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-lock.yaml

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/setup/setupPipPack.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,31 @@ import { getVersion } from "../../default_versions"
1111
import { untildify_user as untildify } from "../path/untildify"
1212

1313
let pip: string | undefined
14+
let python: string = "python3"
1415

1516
let binDir: string | undefined
1617

1718
/** A function that installs a package using pip */
1819
export async function setupPipPack(name: string, version?: string) {
1920
// setup python and pip if needed
2021
if (pip === undefined) {
21-
if (which.sync("pip3", { nothrow: true }) !== null) {
22-
pip = "pip3"
23-
} else if (which.sync("pip", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) {
24-
pip = "pip"
22+
if (process.platform === "win32") {
23+
const installationInfo = await setupPython(getVersion("python", undefined), untildify("python"), process.arch)
24+
if (installationInfo?.installDir !== undefined) {
25+
pip = join(installationInfo.installDir, "Scripts", "pip3.exe")
26+
python = join(installationInfo.installDir, "python.exe")
27+
} else {
28+
pip = "pip3"
29+
}
2530
} else {
26-
await setupPython("3.x", "", process.arch)
27-
pip = "pip3"
28-
}
29-
}
30-
if (process.platform === "win32") {
31-
try {
32-
// test if pip executable is working
33-
await execa(pip, ["--version"], { stdio: "inherit" })
34-
} catch (err) {
35-
await setupPython(getVersion("python", undefined), untildify("python"), process.arch)
36-
pip = "pip3"
31+
if (which.sync("pip3", { nothrow: true }) !== null) {
32+
pip = "pip3"
33+
} else if (which.sync("pip", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) {
34+
pip = "pip"
35+
} else {
36+
await setupPython("3.x", "", process.arch)
37+
pip = "pip3"
38+
}
3739
}
3840
}
3941

@@ -47,9 +49,10 @@ export async function setupPipPack(name: string, version?: string) {
4749
} else if (process.platform === "darwin") {
4850
binDir = "/usr/local/bin/"
4951
} else {
52+
// windows or others
5053
try {
5154
binDir = join(
52-
(await getExecOutput('python3 -c "import sys;print(sys.base_exec_prefix);"')).stdout.trim(),
55+
(await getExecOutput(`${python} -c "import sys;print(sys.base_exec_prefix);"`)).stdout.trim(),
5356
"Scripts"
5457
)
5558
} catch {

0 commit comments

Comments
 (0)