diff --git a/images/capi/hack/utils.sh b/images/capi/hack/utils.sh index 1e8713ff95..6f56495797 100755 --- a/images/capi/hack/utils.sh +++ b/images/capi/hack/utils.sh @@ -102,9 +102,15 @@ ensure_py3() { pip3_install() { ensure_py3 - # Try twice to install in case of "error: externally-managed-environment". - pip3 install --disable-pip-version-check --user "${@}" || \ + if output=$(pip3 install --disable-pip-version-check --user "${@}" 2>&1); then + echo $output + elif [[ $output == *"error: externally-managed-environment"* ]]; then + >&2 echo "warning: externally-managed-environment, retrying pip3 install with --break-system-packages" pip3 install --disable-pip-version-check --user --break-system-packages "${@}" + else + >&2 echo "$output" + exit 1 + fi } hostarch_without_darwin_arm64() {