Skip to content

Commit 01b73c3

Browse files
committed
fix: enforce python version
The previous Python version check was incorrect, allowing installations on unsupported interpreter versions, which caused installation failures. Additionally, we now respect the specified interpreter version if provided, consistently using it throughout the installation process by enforcing it with pip. Signed-off-by: Sébastien Han <seb@redhat.com>
1 parent 743e6f3 commit 01b73c3

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

install/install_requirements.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,39 @@ set -eou pipefail
99

1010
# Install required python dependencies for developing
1111
# Dependencies are defined in .pyproject.toml
12-
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE:-python}
13-
if [[ -z ${CONDA_DEFAULT_ENV:-} ]] || [[ ${CONDA_DEFAULT_ENV:-} == "base" ]] || [[ ! -x "$(command -v python)" ]];
12+
if [ -z "${PYTHON_EXECUTABLE:-}" ];
1413
then
15-
PYTHON_EXECUTABLE=python3
14+
if [[ -z ${CONDA_DEFAULT_ENV:-} ]] || [[ ${CONDA_DEFAULT_ENV:-} == "base" ]] || [[ ! -x "$(command -v python)" ]];
15+
then
16+
PYTHON_EXECUTABLE=python3
17+
fi
1618
fi
19+
echo "Using python executable: $PYTHON_EXECUTABLE"
1720

21+
PYTHON_SYS_VERSION="$($PYTHON_EXECUTABLE -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")"
1822
# Check python version. Expect 3.10.x or 3.11.x
19-
printf "import sys\nif sys.version_info.major != 3 or sys.version_info.minor < 10 :\n\tprint('Please use Python >=3.10');sys.exit(1)\n" | $PYTHON_EXECUTABLE
20-
if [[ $? -ne 0 ]]
23+
if ! $PYTHON_EXECUTABLE -c "
24+
import sys
25+
if sys.version_info < (3, 10) or sys.version_info >= (3, 12):
26+
sys.exit(1)
27+
";
2128
then
29+
echo "Python version must be 3.10.x or 3.11.x. Detected version: $PYTHON_SYS_VERSION"
2230
exit 1
2331
fi
2432

2533
if [[ "$PYTHON_EXECUTABLE" == "python" ]];
2634
then
2735
PIP_EXECUTABLE=pip
28-
else
36+
elif [[ "$PYTHON_EXECUTABLE" == "python3" ]];
37+
then
2938
PIP_EXECUTABLE=pip3
39+
else
40+
PIP_EXECUTABLE=pip${PYTHON_SYS_VERSION}
3041
fi
3142

43+
echo "Using pip executable: $PIP_EXECUTABLE"
44+
3245
#
3346
# First install requirements in install/requirements.txt. Older torch may be
3447
# installed from the dependency of other models. It will be overridden by

0 commit comments

Comments
 (0)