Skip to content

Commit 92b1a47

Browse files
author
Thierry RAMORASOAVINA
committed
Fix the detection of unhappy installation paths under Windows
- External tools like VSCode can modify for example the case of the path saved in `sys.executable` - As a general rule paths under Windows are case-insensitive
1 parent b81ec6e commit 92b1a47

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
### Fixed
1515
- (`sklearn`) Default value of `n_features` for the supervised estimators
16+
- (`core`) Detection of an unhappy installation path in a venv under Windows
1617

1718
## 11.0.0.2 - 2026-01-26
1819

khiops/core/internals/runner.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,14 @@ def _detect_library_installation_incompatibilities(self, library_root_dir):
11721172
)
11731173
warning_list.append(warning)
11741174

1175+
os_dependent_library_root_dir = str(library_root_dir)
1176+
os_dependent_conda_prefix = os.environ["CONDA_PREFIX"]
1177+
if platform.system() == "Windows":
1178+
# warning : paths are case-insensitive under Windows
1179+
os_dependent_library_root_dir = os_dependent_library_root_dir.lower()
1180+
os_dependent_conda_prefix = os_dependent_conda_prefix.lower()
11751181
# the conda environment must match the library installation
1176-
if not str(library_root_dir).startswith(os.environ["CONDA_PREFIX"]):
1182+
if not os_dependent_library_root_dir.startswith(os_dependent_conda_prefix):
11771183
error = (
11781184
f"Khiops Python library installation path '{library_root_dir}' "
11791185
"does not match the current Conda environment "
@@ -1184,9 +1190,13 @@ def _detect_library_installation_incompatibilities(self, library_root_dir):
11841190
"Go to https://khiops.org for instructions.\n"
11851191
)
11861192
error_list.append(error)
1193+
os_dependent_khiops_path = self.khiops_path
1194+
if platform.system() == "Windows":
1195+
# warning : paths are case-insensitive under Windows
1196+
os_dependent_khiops_path = os_dependent_khiops_path.lower()
11871197
# the khiops executable path must also match the conda environment one
11881198
# meaning khiops core was installed using conda
1189-
if not self.khiops_path.startswith(os.environ["CONDA_PREFIX"]):
1199+
if not os_dependent_khiops_path.startswith(os_dependent_conda_prefix):
11901200
error = (
11911201
f"Khiops binary path '{self.khiops_path}' "
11921202
"does not match the current Conda environment "
@@ -1226,11 +1236,17 @@ def _detect_library_installation_incompatibilities(self, library_root_dir):
12261236
# no further check cannot be performed)
12271237
base_dir = _infer_base_dir_for_conda_based_or_pip_installations()
12281238
if len(base_dir) > 0:
1239+
os_dependent_base_prefix = sys.base_prefix
1240+
os_dependent_sys_prefix = sys.prefix
1241+
if platform.system() == "Windows":
1242+
# warning : paths are case-insensitive under Windows
1243+
os_dependent_base_prefix = os_dependent_base_prefix.lower()
1244+
os_dependent_sys_prefix = os_dependent_sys_prefix.lower()
12291245
# within a virtual env, sys.prefix is set to the virtual env folder
12301246
# whereas sys.base_prefix remains unchanged.
12311247
# Please be aware that if a python executable of a virtual env is used
12321248
# the corresponding virtual env is activated and sys.prefix updated
1233-
if sys.base_prefix != sys.prefix:
1249+
if os_dependent_base_prefix != os_dependent_sys_prefix:
12341250
# the python executable location
12351251
# (within the virtual env or the conda-based env)
12361252
# must match the library installation
@@ -1240,11 +1256,15 @@ def _detect_library_installation_incompatibilities(self, library_root_dir):
12401256
# Under Windows, there are two cases :
12411257
(
12421258
# for conda-based installations python is inside 'base_dir'
1243-
str(Path(sys.executable).parents[0]) != base_dir
1259+
# warning : paths are case-insensitive under Windows
1260+
str(Path(sys.executable.lower()).parents[0])
1261+
!= base_dir.lower()
12441262
and
12451263
# for 'binary+pip' installations (within a virtual env)
12461264
# python is inside 'base_dir'/Scripts
1247-
str(Path(sys.executable).parents[1]) != base_dir
1265+
# warning : paths are case-insensitive under Windows
1266+
str(Path(sys.executable.lower()).parents[1])
1267+
!= base_dir.lower()
12481268
)
12491269
# Under Linux or MacOS a bin/ folder exists
12501270
or str(Path(sys.executable).parents[1]) != base_dir
@@ -1260,9 +1280,15 @@ def _detect_library_installation_incompatibilities(self, library_root_dir):
12601280
)
12611281
error_list.append(error)
12621282
else:
1283+
os_dependent_sys_exec = sys.executable
1284+
os_dependent_base_prefix = sys.base_prefix
1285+
if platform.system() == "Windows":
1286+
# warning : paths are case-insensitive under Windows
1287+
os_dependent_sys_exec = os_dependent_sys_exec.lower()
1288+
os_dependent_base_prefix = os_dependent_base_prefix.lower()
12631289
# the installation is not within a virtual env
12641290
# (sys.base_prefix == sys.prefix)
1265-
if not sys.executable.startswith(sys.base_prefix):
1291+
if not os_dependent_sys_exec.startswith(os_dependent_base_prefix):
12661292
# the executable is not the expected one
12671293
# (the system-wide python)
12681294
error = (
@@ -1281,9 +1307,19 @@ def _detect_library_installation_incompatibilities(self, library_root_dir):
12811307
# fetch the 'User site' site-packages path
12821308
# which is already adapted for each OS (Windows, MacOS, Linux)
12831309
user_site_packages_dir = site.getusersitepackages()
1284-
if not str(library_root_dir).startswith(user_site_packages_dir):
1310+
os_dependent_library_root_dir = str(library_root_dir)
1311+
if platform.system() == "Windows":
1312+
# warning : paths are case-insensitive under Windows
1313+
os_dependent_library_root_dir = (
1314+
os_dependent_library_root_dir.lower()
1315+
)
1316+
if not os_dependent_library_root_dir.startswith(
1317+
user_site_packages_dir
1318+
):
12851319
# the library is not installed on the 'User site'
1286-
if not str(library_root_dir).startswith(sys.base_prefix):
1320+
if not os_dependent_library_root_dir.startswith(
1321+
os_dependent_base_prefix
1322+
):
12871323
# the library is supposed to be installed system-wide,
12881324
# but it seems that the location is wrong
12891325
error = (

0 commit comments

Comments
 (0)