Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[PyOV] Revert dynamic discovery of Python version in setupvars scripts (#37554)

Przemyslaw Wysocki16f91e919618
diff --git a/scripts/setupvars/setupvars.bat b/scripts/setupvars/setupvars.bat
index 90c67089561..18105820562 100644
--- a/scripts/setupvars/setupvars.bat
+++ b/scripts/setupvars/setupvars.bat
@@ -66,6 +66,10 @@ if exist %INTEL_OPENVINO_DIR%\runtime\3rdparty\tbb (
set "PATH=%OPENVINO_LIB_PATHS%;%PATH%"
:: Check if Python is installed
+set PYTHON_VERSION_MAJOR=3
+set MIN_REQUIRED_PYTHON_VERSION_MINOR=10
+set MAX_SUPPORTED_PYTHON_VERSION_MINOR=14
+
python --version 2>NUL
if errorlevel 1 (call :python_not_installed) else (call :check_python_version)
@@ -74,12 +78,7 @@ echo [setupvars.bat] OpenVINO environment initialized
exit /B 0
:python_not_installed
-call :get_available_python_versions
-if "%available_python_versions%"=="" (
- echo Warning^: Python is not installed. Please install Python ^(64-bit^) from https://www.python.org/downloads/
-) else (
- echo Warning^: Python is not installed. Please install one of Python%available_python_versions% ^(64-bit^) from https://www.python.org/downloads/
-)
+echo Warning^: Python is not installed. Please install one of Python %PYTHON_VERSION_MAJOR%.%MIN_REQUIRED_PYTHON_VERSION_MINOR% - %PYTHON_VERSION_MAJOR%.%MAX_SUPPORTED_PYTHON_VERSION_MINOR% ^(64-bit^) from https://www.python.org/downloads/
exit /B 0
:check_python_version
@@ -96,24 +95,21 @@ for /F "tokens=1,2 delims=. " %%a in ("%python_version%") do (
)
:: Strip non-numeric suffix from minor version (e.g., 14t -> 14)
-for /f "delims=t" %%i in ("%pyversion_minor%") do set "pyversion_minor=%%i"
+call :strip_suffix pyversion_minor
-set "current_python_version=%pyversion_major%.%pyversion_minor%"
-
-call :get_available_python_versions
-if "%available_python_versions%"=="" (
- echo Warning^: Could not detect which Python versions the OpenVINO Python API in this package was built for. The installed Python version will not be verified.
- goto :python_version_ok
+if %pyversion_major% equ %PYTHON_VERSION_MAJOR% (
+ if %pyversion_minor% geq %MIN_REQUIRED_PYTHON_VERSION_MINOR% (
+ if %pyversion_minor% leq %MAX_SUPPORTED_PYTHON_VERSION_MINOR% (
+ set "check_pyversion=true"
+ )
+ )
)
-set "check_pyversion="
-for %%v in (%available_python_versions%) do call :match_python_version "%%v"
-if "%check_pyversion%"=="true" goto :python_version_ok
-
-echo Unsupported Python version %current_python_version%. The OpenVINO Python API in this package is built for Python:%available_python_versions%. Please activate a Python environment with a matching version.
-exit /B 0
+if not "%check_pyversion%"=="true" (
+ echo Unsupported Python version %pyversion_major%.%pyversion_minor%. Please install one of Python %PYTHON_VERSION_MAJOR%.%MIN_REQUIRED_PYTHON_VERSION_MINOR% - %PYTHON_VERSION_MAJOR%.%MAX_SUPPORTED_PYTHON_VERSION_MINOR% ^(64-bit^) from https://www.python.org/downloads/
+ exit /B 0
+)
-:python_version_ok
:: Check Python bitness
python -c "import sys; print(64 if sys.maxsize > 2**32 else 32)" 2 > NUL
if errorlevel 1 (
@@ -126,36 +122,13 @@ for /F "tokens=* USEBACKQ" %%F IN (`python -c "import sys; print(64 if sys.maxsi
)
if not "%bitness%"=="64" (
- echo Unsupported Python bitness. Please install a 64-bit Python interpreter from https://www.python.org/downloads/
+ echo Unsupported Python bitness. Please install one of Python %PYTHON_VERSION_MAJOR%.%MIN_REQUIRED_PYTHON_VERSION_MINOR% - %PYTHON_VERSION_MAJOR%.%MAX_SUPPORTED_PYTHON_VERSION_MINOR%^(64-bit^) from https://www.python.org/downloads/
exit /B 0
)
set PYTHONPATH=%INTEL_OPENVINO_DIR%\python;%INTEL_OPENVINO_DIR%\python\python3;%PYTHONPATH%
exit /B 0
-:get_available_python_versions
-set "available_python_versions="
-set "ov_python_dir=%INTEL_OPENVINO_DIR%\python\openvino"
-if not exist "%ov_python_dir%" exit /B 0
-if not exist "%ov_python_dir%\_pyopenvino.cp*.pyd" exit /B 0
-for %%F in ("%ov_python_dir%\_pyopenvino.cp*.pyd") do call :parse_pyd_version "%%~nxF"
-exit /B 0
-
-:parse_pyd_version
-:: %1 is a file name like _pyopenvino.cp312-win_amd64.pyd
-set "fname=%~1"
-set "tag=%fname:*_pyopenvino.cp=%"
-for /f "delims=-" %%A in ("%tag%") do set "vernum=%%A"
-call :strip_suffix vernum
-set "ver=%vernum:~0,1%.%vernum:~1%"
-echo %available_python_versions% | findstr /C:" %ver%" >NUL 2>&1 || set "available_python_versions=%available_python_versions% %ver%"
-set "ver="
-exit /B 0
-
-:match_python_version
-if "%~1"=="%current_python_version%" set "check_pyversion=true"
-exit /B 0
-
:strip_suffix
:: Remove non-numeric suffix from a version number variable
:: Usage: call :strip_suffix variable_name
diff --git a/scripts/setupvars/setupvars.ps1 b/scripts/setupvars/setupvars.ps1
index 447285ca2c6..d61e6c8e9a5 100644
--- a/scripts/setupvars/setupvars.ps1
+++ b/scripts/setupvars/setupvars.ps1
@@ -62,28 +62,9 @@ $Env:PATH = "$Env:OPENVINO_LIB_PATHS;$Env:PATH"
Write-Host "[setupvars] OpenVINO environment initialized"
# Check if Python is installed
-
-function Get-AvailablePythonVersions
-{
- $ov_python_dir = Join-Path $Env:INTEL_OPENVINO_DIR "python/openvino"
- $versions = @()
- if (Test-Path -Path $ov_python_dir)
- {
- foreach ($lib in Get-ChildItem -Path $ov_python_dir -Filter "_pyopenvino.*" -ErrorAction SilentlyContinue)
- {
- if ($lib.Name -match '_pyopenvino\.(?:cpython-|cp)(\d+)')
- {
- $tag = $matches[1]
- $version = "$($tag.Substring(0, 1)).$($tag.Substring(1))"
- if ($versions -notcontains $version)
- {
- $versions += $version
- }
- }
- }
- }
- return $versions
-}
+$PYTHON_VERSION_MAJOR = 3
+$MIN_REQUIRED_PYTHON_VERSION_MINOR = 10
+$MAX_SUPPORTED_PYTHON_VERSION_MINOR = 14
try
{
@@ -92,15 +73,7 @@ try
}
catch
{
- $available_python_versions = @(Get-AvailablePythonVersions)
- if ($available_python_versions.Count -gt 0)
- {
- Write-Host "Warning: Python is not installed. Please install one of Python $($available_python_versions -join ', ') (64-bit) from https://www.python.org/downloads/"
- }
- else
- {
- Write-Host "Warning: Python is not installed. Please install Python (64-bit) from https://www.python.org/downloads/"
- }
+ Write-Host "Warning: Python is not installed. Please install one of Python $PYTHON_VERSION_MAJOR.$MIN_REQUIRED_PYTHON_VERSION_MINOR - $PYTHON_VERSION_MAJOR.$MAX_SUPPORTED_PYTHON_VERSION_MINOR (64-bit) from https://www.python.org/downloads/"
# Python is not mandatory so we can safely exit with 0
Exit 0
}
@@ -120,16 +93,9 @@ else
$installed_python_version_minor = [int]$minor_version_string
}
-$current_python_version = "$installed_python_version_major.$installed_python_version_minor"
-$available_python_versions = @(Get-AvailablePythonVersions)
-
-if ($available_python_versions.Count -eq 0)
-{
- Write-Host "Warning: Could not detect which Python versions the OpenVINO Python API in this package was built for. The installed Python version will not be verified."
-}
-elseif ($available_python_versions -notcontains $current_python_version)
+if (-not ($PYTHON_VERSION_MAJOR -eq $installed_python_version_major -and $installed_python_version_minor -ge $MIN_REQUIRED_PYTHON_VERSION_MINOR -and $installed_python_version_minor -le $MAX_SUPPORTED_PYTHON_VERSION_MINOR))
{
- Write-Host "Warning: Unsupported Python version $current_python_version. The OpenVINO Python API in this package is built for Python: $($available_python_versions -join ', '). Please activate a Python environment with a matching version."
+ Write-Host "Warning: Unsupported Python version $installed_python_version_major.$installed_python_version_minor. Please install one of Python $PYTHON_VERSION_MAJOR.$MIN_REQUIRED_PYTHON_VERSION_MINOR - $PYTHON_VERSION_MAJOR.$MAX_SUPPORTED_PYTHON_VERSION_MINOR (64-bit) from https://www.python.org/downloads/"
# Python is not mandatory so we can safely exit with 0
Exit 0
}
@@ -149,7 +115,7 @@ catch
if ($python_bitness -ne "64")
{
- Write-Host "Warning: Unsupported Python bitness. Please install a 64-bit Python interpreter from https://www.python.org/downloads/"
+ Write-Host "Warning: Unsupported Python bitness. Please install one of Python $PYTHON_VERSION_MAJOR.$MIN_REQUIRED_PYTHON_VERSION_MINOR - $PYTHON_VERSION_MAJOR.$MAX_SUPPORTED_PYTHON_VERSION_MINOR (64-bit) from https://www.python.org/downloads/"
# Python is not mandatory so we can safely exit with 0
Exit 0
}
diff --git a/scripts/setupvars/setupvars.sh b/scripts/setupvars/setupvars.sh
index 1e2f1247ab2..8a3c88a5f09 100755
--- a/scripts/setupvars/setupvars.sh
+++ b/scripts/setupvars/setupvars.sh
@@ -99,22 +99,9 @@ if command -v lsb_release >/dev/null 2>&1; then
OS_NAME=$(lsb_release -i -s)
fi
-get_available_python_versions () {
- available_python_versions=""
- ov_python_dir="$INTEL_OPENVINO_DIR/python/openvino"
- if [ -d "$ov_python_dir" ]; then
- for lib in "$ov_python_dir"/_pyopenvino.cpython-*.so; do
- [ -e "$lib" ] || continue
- ver_tag=$(basename "$lib" | sed -n 's/^_pyopenvino\.cpython-\([0-9][0-9]*\)[a-z]*-.*/\1/p')
- [ -z "$ver_tag" ] && continue
- ver_str="${ver_tag%"${ver_tag#?}"}.${ver_tag#?}"
- case " $available_python_versions " in
- *" $ver_str "*) ;;
- *) available_python_versions="${available_python_versions:+$available_python_versions }$ver_str" ;;
- esac
- done
- fi
-}
+PYTHON_VERSION_MAJOR="3"
+MIN_REQUIRED_PYTHON_VERSION_MINOR="10"
+MAX_SUPPORTED_PYTHON_VERSION_MINOR="14"
check_python_version () {
if [ -z "$python_version" ]; then
@@ -128,28 +115,15 @@ check_python_version () {
# Strip non-numeric suffix from minor version (e.g., 14t -> 14)
python_version_minor_numeric="${python_version_minor%%[!0-9]*}"
- current_python_version="${python_version_major}.${python_version_minor_numeric}"
- get_available_python_versions
-
- if [ -n "$available_python_versions" ]; then
- version_supported=""
- for v in $available_python_versions; do
- if [ "$v" = "$current_python_version" ]; then
- version_supported="yes"
- break
- fi
- done
- if [ -z "$version_supported" ]; then
- echo "[setupvars.sh] WARNING: Unsupported Python version ${current_python_version}." \
- "The OpenVINO Python API in this package is built for Python: ${available_python_versions}." \
- "Please activate a Python environment with a matching version."
- unset python_version
- return 0
- fi
- else
- echo "[setupvars.sh] WARNING: Could not detect which Python versions the OpenVINO Python API" \
- "in this package was built for. The installed Python version will not be verified."
+ if [ "$PYTHON_VERSION_MAJOR" != "$python_version_major" ] ||
+ [ "$python_version_minor_numeric" -lt "$MIN_REQUIRED_PYTHON_VERSION_MINOR" ] ||
+ [ "$python_version_minor_numeric" -gt "$MAX_SUPPORTED_PYTHON_VERSION_MINOR" ] ; then
+ echo "[setupvars.sh] WARNING: Unsupported Python version ${python_version}. Please install one of Python" \
+ "${PYTHON_VERSION_MAJOR}.${MIN_REQUIRED_PYTHON_VERSION_MINOR} -" \
+ "${PYTHON_VERSION_MAJOR}.${MAX_SUPPORTED_PYTHON_VERSION_MINOR} (64-bit) from https://www.python.org/downloads/"
+ unset python_version
+ return 0
fi
if command -v python"$python_version" > /dev/null 2>&1; then
@@ -184,21 +158,18 @@ if [ -z "$python_version" ]; then
fi
if ! command -v python"$python_version_to_check" > /dev/null 2>&1; then
- get_available_python_versions
- if [ -n "$available_python_versions" ]; then
- echo "[setupvars.sh] WARNING: Python is not installed. Please install one of Python" \
- "${available_python_versions} (64-bit) from https://www.python.org/downloads/"
- else
- echo "[setupvars.sh] WARNING: Python is not installed." \
- "Please install Python (64-bit) from https://www.python.org/downloads/"
- fi
+ echo "[setupvars.sh] WARNING: Python is not installed. Please install one of Python" \
+ "${PYTHON_VERSION_MAJOR}.${MIN_REQUIRED_PYTHON_VERSION_MINOR} -" \
+ "${PYTHON_VERSION_MAJOR}.${MAX_SUPPORTED_PYTHON_VERSION_MINOR} (64-bit) from https://www.python.org/downloads/"
else
check_python_version
fi
unset python_version
unset python_version_to_check
-unset available_python_versions
+unset PYTHON_VERSION_MAJOR
+unset MIN_REQUIRED_PYTHON_VERSION_MINOR
+unset MAX_SUPPORTED_PYTHON_VERSION_MINOR
unset OS_NAME
echo "[setupvars.sh] OpenVINO environment initialized"