Skip to content

Commit b7f10af

Browse files
committed
fix: install pip packages using python executable
1 parent 94827f0 commit b7f10af

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
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.

src/utils/setup/setupPipPack.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,34 @@ import { setupPython } from "../../python/python"
88
import { isBinUptoDate } from "./version"
99
import { join } from "path"
1010
import { getVersion } from "../../default_versions"
11+
import { InstallationInfo } from "./setupBin"
1112

12-
let pip: string | undefined
13-
13+
let python: string | undefined
1414
let binDir: string | undefined
1515

16+
let tried = false
17+
1618
/** A function that installs a package using pip */
17-
export async function setupPipPack(name: string, version?: string) {
19+
export async function setupPipPack(name: string, version?: string): Promise<InstallationInfo> {
1820
// setup python and pip if needed
19-
if (pip === undefined) {
20-
if (which.sync("pip3", { nothrow: true }) !== null) {
21-
pip = "pip3"
22-
} else if (which.sync("pip", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) {
23-
pip = "pip"
21+
if (python === undefined) {
22+
if (which.sync("python3", { nothrow: true }) !== null) {
23+
python = "python3"
24+
} else if (which.sync("python", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) {
25+
python = "python"
2426
} else {
25-
info("pip3 was not found. Installing python")
27+
info("python3 was not found. Installing python")
2628
await setupPython(getVersion("python", undefined), "", process.arch)
27-
pip = "pip3"
29+
// try again
30+
if (tried) {
31+
throw new Error("Failed to install python")
32+
}
33+
tried = true
34+
return setupPipPack(name, version)
2835
}
2936
}
3037

31-
execa.sync(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
38+
execa.sync(python, ["-m", "pip", "install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
3239
stdio: "inherit",
3340
})
3441

@@ -41,12 +48,12 @@ export async function setupPipPack(name: string, version?: string) {
4148
// windows or others
4249
try {
4350
binDir = join(
44-
(await getExecOutput(`python3 -c "import sys;print(sys.base_exec_prefix);"`)).stdout.trim(),
51+
(await getExecOutput(`${python} -c "import sys;print(sys.base_exec_prefix);"`)).stdout.trim(),
4552
"Scripts"
4653
)
4754
} catch {
4855
binDir = join(
49-
(await getExecOutput('python -c "import sys;print(sys.base_exec_prefix);"')).stdout.trim(),
56+
(await getExecOutput(`${python} -c "import sys;print(sys.base_exec_prefix);"`)).stdout.trim(),
5057
"Scripts"
5158
)
5259
}

0 commit comments

Comments
 (0)