Skip to content

Commit ce9c1a5

Browse files
Check pip availability before running ensurepip (#392)
* Check pip availability before running ensurepip * check ensurepip exit code in Windows installer Add error handling for ensurepip execution and pip installation. * Suppress stderr on Windows pip check
1 parent b3ab7a2 commit ce9c1a5

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

installers/macos-pkg-setup-template.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ chmod +x $PYTHON_MAJOR $PYTHON_MAJOR_DOT_MINOR $PYTHON_MAJOR_MINOR python
8484

8585
echo "Upgrading pip..."
8686
export PIP_ROOT_USER_ACTION=ignore
87-
./python -m ensurepip
87+
if ! ./python -c "import pip" 2>/dev/null; then
88+
./python -m ensurepip
89+
fi
8890
./python -m pip install --upgrade --force-reinstall pip --disable-pip-version-check --no-warn-script-location
8991

9092
echo "Install OpenSSL certificates"

installers/nix-setup-template.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ chmod +x ../python $PYTHON_MAJOR $PYTHON_MAJOR_DOT_MINOR $PYTHON_MAJORMINOR pyth
5151

5252
echo "Upgrading pip..."
5353
export PIP_ROOT_USER_ACTION=ignore
54-
./python -m ensurepip
54+
if ! ./python -c "import pip" 2>/dev/null; then
55+
./python -m ensurepip
56+
fi
5557
./python -m pip install --upgrade --force-reinstall pip --disable-pip-version-check --no-warn-script-location
5658

5759
echo "Create complete file"

installers/win-setup-template.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,14 @@ New-Item -Path "$PythonArchPath\python3.exe" -ItemType SymbolicLink -Value "$Pyt
143143
Write-Host "Install and upgrade Pip"
144144
$Env:PIP_ROOT_USER_ACTION = "ignore"
145145
$PythonExePath = Join-Path -Path $PythonArchPath -ChildPath "python.exe"
146-
cmd.exe /c "$PythonExePath -m ensurepip && $PythonExePath -m pip install --upgrade --force-reinstall pip --no-warn-script-location"
146+
cmd.exe /c "$PythonExePath -c ""import pip"" 2>NUL"
147+
if ($LASTEXITCODE -ne 0) {
148+
cmd.exe /c "$PythonExePath -m ensurepip"
149+
if ($LASTEXITCODE -ne 0) {
150+
Throw "Error happened during ensurepip execution"
151+
}
152+
}
153+
cmd.exe /c "$PythonExePath -m pip install --upgrade --force-reinstall pip --no-warn-script-location"
147154
if ($LASTEXITCODE -ne 0) {
148155
Throw "Error happened during pip installation / upgrade"
149156
}

0 commit comments

Comments
 (0)