@@ -29,7 +29,8 @@ if [ -f "$(pwd)/build/venv/bin/activate" ]; then
2929 fi
3030fi
3131
32- if ! command -v pip3 > /dev/null 2>&1 && [ ! -f " $( pwd) /build/venv/bin/activate" ]; then
32+ # Only bootstrap pip if we don't already have a venv
33+ if [ ! -f " $( pwd) /build/venv/bin/activate" ]; then
3334 # Check whether python3 is in the $PATH / is accessible.
3435 if ! command -v python3 > /dev/null 2>&1 ; then
3536 error " Couldn't find$MAGENTA Python$COLOR_RESET . Please ensure it is discoverable."
@@ -39,26 +40,41 @@ if ! command -v pip3 > /dev/null 2>&1 && [ ! -f "$(pwd)/build/venv/bin/activate"
3940
4041 assert_python_compatible
4142
42- get_pip_url=" https://bootstrap.pypa.io/pip/get-pip.py"
43-
44- warn " $MAGENTA " " Python$COLOR_RESET 's$MAGENTA PIP$COLOR_RESET is not installed."
45- log " Downloading$MAGENTA Python$COLOR_RESET 's$MAGENTA PIP$COLOR_RESET from $get_pip_url ..."
46-
47- if ! wget -O " $( pwd) /build/get-pip.py" " $get_pip_url " ; then
48- error " Couldn't download get-pip.py."
49-
50- exit 1
51- fi
52-
53- # Suppress PIP version warning (out of date)
54- export PIP_DISABLE_PIP_VERSION_CHECK=1
55- if ! python3 " $( pwd) /build/get-pip.py" --user; then
56- error " Couldn't install$MAGENTA pip$COLOR_RESET with get-pip.py"
57-
58- exit 1
43+ # Check if pip is already available as a Python module
44+ # This works on both laptops and HPC systems with module-loaded Python
45+ if ! python3 -c " import pip" > /dev/null 2>&1 ; then
46+ warn " $MAGENTA " " Python$COLOR_RESET 's$MAGENTA PIP$COLOR_RESET is not installed."
47+
48+ # Try ensurepip first (standard library, safe)
49+ log " Attempting to install pip via ensurepip..."
50+ if python3 -m ensurepip --upgrade 2> /dev/null; then
51+ ok " Installed pip via ensurepip."
52+ else
53+ # Fall back to get-pip.py only if ensurepip fails
54+ get_pip_url=" https://bootstrap.pypa.io/pip/get-pip.py"
55+ log " Downloading$MAGENTA Python$COLOR_RESET 's$MAGENTA PIP$COLOR_RESET from $get_pip_url ..."
56+
57+ if ! wget -O " $( pwd) /build/get-pip.py" " $get_pip_url " ; then
58+ error " Couldn't download get-pip.py."
59+ exit 1
60+ fi
61+
62+ # Suppress PIP version warning (out of date)
63+ export PIP_DISABLE_PIP_VERSION_CHECK=1
64+ if ! python3 " $( pwd) /build/get-pip.py" --user; then
65+ error " Couldn't install$MAGENTA pip$COLOR_RESET with get-pip.py"
66+ exit 1
67+ fi
68+
69+ ok " Installed pip via get-pip.py."
70+
71+ # Ensure user-site bin directory is on PATH for this session
72+ user_base_bin=" $( python3 -m site --user-base) /bin"
73+ if [ -d " $user_base_bin " ]; then
74+ export PATH=" $user_base_bin :$PATH "
75+ fi
76+ fi
5977 fi
60-
61- ok " Installed pip."
6278fi
6379
6480
0 commit comments