@@ -11,29 +11,31 @@ import { getVersion } from "../../default_versions"
11
11
import { untildify_user as untildify } from "../path/untildify"
12
12
13
13
let pip : string | undefined
14
+ let python : string = "python3"
14
15
15
16
let binDir : string | undefined
16
17
17
18
/** A function that installs a package using pip */
18
19
export async function setupPipPack ( name : string , version ?: string ) {
19
20
// setup python and pip if needed
20
21
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
+ }
25
30
} 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
+ }
37
39
}
38
40
}
39
41
@@ -47,9 +49,10 @@ export async function setupPipPack(name: string, version?: string) {
47
49
} else if ( process . platform === "darwin" ) {
48
50
binDir = "/usr/local/bin/"
49
51
} else {
52
+ // windows or others
50
53
try {
51
54
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 ( ) ,
53
56
"Scripts"
54
57
)
55
58
} catch {
0 commit comments