Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,42 @@ jobs:
"$PYTHON" scripts/extract_dependencies_from_pyproject_toml.py -f "pyproject.toml" --khiops-family-only > requires-khiops.txt
"$PYTHON" -m pip install --index-url https://test.pypi.org/simple `cat requires-khiops.txt`
rm -f requires-khiops.txt requires-no-khiops.txt
- name: Install Uv
uses: astral-sh/setup-uv@v10.3.2
with:
enable-cache: false
version: 0.13.5
python-version: '3.14'
- name: Test Khiops when run with Uv
run: |-
# Create virtual environment
uv venv

# Get khiops-core version specification from pyproject.toml, as
# "khiops-core<op>x.y.z[-pre]", where "op" is one of "==", "<",
# "<=", ">", ">=".
KHIOPS_CORE_SPEC=$(uv run --no-project --with packaging python - <<'EOF'
import tomllib
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name
with open("pyproject.toml", "rb") as pyproject_file:
dependencies = tomllib.load(pyproject_file)["project"]["dependencies"]
for package in dependencies:
if canonicalize_name(Requirement(package).name) == "khiops-core":
print(package)
break
EOF
)

# With --no-deps, MPI is not installed at this stage; it will be later,
# on "uv pip install ."
uv pip install --no-deps --index-url https://test.pypi.org/simple/ "$KHIOPS_CORE_SPEC"

# Install all remaining khiops (and khiops-core) dependencies from PyPI
uv pip install .
Comment thread
popescu-v marked this conversation as resolved.
Resolved

# Run the status tool (without activating explicitly the virtual environment)
uv run kh-status
- name: Setup and Install Test Requirements
shell: bash
run: |-
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

## Unreleased

### Removed
- (General) Python 3.10 support.
### Added
- (`general`) Uv installation support.

### Fixed
- (General) Built packages with up-to-date packaging-tools after the emSign CA
incident.

### Removed
- (General) Python 3.10 support.

## 11.0.1.1 - 2026-10-15

### Added
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,36 @@ conda activate khiops-env
conda install -c conda-forge khiops
```

Using `pip` under Linux (in a `bash` shell)
Under Linux (in a `bash` shell)

Using `pip`:
```bash
python -m venv khiops-venv
source khiops-venv/bin/activate
pip install -U khiops
```

Using `pip` under Windows (in a `powershell` shell)
Using `uv`:
```bash
uv venv
uv pip install -U khiops
```

Under Windows (in a `powershell` shell)

Using `pip`:
```shell
python -m venv khiops-venv
khiops-venv\Scripts\activate
pip install -U khiops
```

Using `uv`:
```shell
uv venv
uv pip install -U khiops
```

Other installation methods are documented at the [Khiops website][khiops-install].

### Requirements
Expand Down
17 changes: 16 additions & 1 deletion doc/site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,38 @@ Welcome to the Khiops Python API documentation page.

## Installation

Khiops can be installed in a Python virtual environment using `pip`,
Khiops can be installed in a Python virtual environment using `pip` or `uv`,
under Linux and macOS (in a `bash` shell):

Using `pip`:
```bash
python -m venv khiops-venv
source khiops-venv/bin/activate
pip install -U khiops
```

Using `uv`:
```bash
uv venv
uv pip install -U khiops
```


under Windows (in a `powershell` shell):

Using `pip`:
```powershell
python -m venv khiops-venv
khiops-venv\Scripts\activate
pip install -U khiops
```

Using `uv`:
```powershell
uv venv
uv pip install -U khiops
```

Alternatively, you can install Khiops with the [Conda package manager](https://docs.conda.io/en/latest/):

```bash
Expand Down
104 changes: 47 additions & 57 deletions khiops/core/internals/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
# Path(__file__).

"""Classes implementing Khiops Python' backend runners"""

import importlib
import io
import os
import platform
import shlex
import shutil
import site
import subprocess
import sys
import sysconfig
Expand Down Expand Up @@ -265,11 +264,12 @@ def _infer_khiops_installation_method(environment=None, trace=False):
and the path to the `bin/` directory inside the Conda environment is not in
PATH
- 'pip' environment containing binaries, shared libraries and the Python libraries
can either be:
can either be (user-site installation is not supported):
- system-wide (strongly discouraged)
- or in the Python folder inside the home directory of the user
(a.k.a. "User site")
- or in a classical virtual environment (highly encouraged)
- 'uv' dedicated environment contains binaries, shared libraries and
the Python libraries
- 'unknown' is returned if no matching installation method is found

"""
environment = _current_environment(environment)
Expand All @@ -290,8 +290,8 @@ def _infer_khiops_installation_method(environment=None, trace=False):
conda_binary_dir = os.path.join(conda_env_dir, "bin")
if _khiops_env_file_exists(conda_binary_dir):
installation_method = "conda"
# Otherwise (installation_method is still "unknown"), we choose between
# conda-based and local (default choice)
# Otherwise (installation_method is still "unknown"), the guessing must continue
# between 'conda-based', 'pip' or 'uv'
if installation_method == "unknown":
env_bin_dir = _infer_env_bin_dir_for_conda_based_installations()
if trace:
Expand All @@ -301,10 +301,27 @@ def _infer_khiops_installation_method(environment=None, trace=False):
):
installation_method = "conda-based"
else:
installation_method = "pip"
environment_configuration_file = Path(
os.path.join(sys.prefix, "pyvenv.cfg")
)
if environment_configuration_file.is_file():
# Check an installation in a virtual environment (using 'pip' or 'uv')
keys = {
line.split("=", 1)[0].strip()
for line in environment_configuration_file.read_text().splitlines()
if "=" in line
}
if "uv" in keys:
installation_method = "uv"
elif "virtualenv" in keys or "command" in keys:
installation_method = "pip"
else:
# Check a system-wide installation (using 'pip')
if importlib.util.find_spec("khiops") is not None:
installation_method = "pip"
if trace:
print(f"Installation method: '{installation_method}'")
assert installation_method in ("conda", "conda-based", "pip")
assert installation_method in ("unknown", "conda", "conda-based", "pip", "uv")
return installation_method


Expand All @@ -323,7 +340,7 @@ def _get_current_library_installer():
Returns
-------
str
installer name among : 'pip', 'conda' or 'unknown'
installer name among : 'pip', 'uv', 'conda' or 'unknown'
"""

try:
Expand All @@ -345,12 +362,12 @@ def _get_current_library_installer():
warnings.warn(
"The python library metadata exists ('khiops-*.dist-info') "
"but seems corrupted as no INSTALLER file can be found. "
"Please re-install using the same tool ('conda' or 'pip').",
"Please re-install using the same tool ('conda', 'pip' or 'uv').",
stacklevel=3,
)
return "unknown"
except PackageNotFoundError:
# The python library is not installed via standard tools like conda, pip...
# The python library is not installed via standard tools like conda, pip, uv
return "unknown"


Expand Down Expand Up @@ -1017,7 +1034,7 @@ def _initialize_khiops_environment(self):
khiops_env_path = self._infer_khiops_env_from_path(
installation_method, runner_environment
)
case "pip":
case "pip" | "uv":
# Ensure the binary dependency is still installed.
try:
distribution("khiops-core")
Expand All @@ -1027,29 +1044,18 @@ def _initialize_khiops_environment(self):
"Re-install the Khiops Python library to automatically install "
"Khiops. Go to https://khiops.org for more information.\n"
) from exc
# On Windows, determine the Scripts directory where pip placed
# khiops_env.cmd.
# If this library is installed under the user site-packages
# directory, khiops-core (and its khiops_env.cmd) was also installed
# there with `pip install --user`, so use the user Scripts directory.
# Otherwise use the standard Scripts directory (venv or system-wide
# install). This avoids an ambiguous search and mirrors how pip
# resolves scripts.
# On Windows, determine the Scripts directory where pip or uv placed
# khiops_env.cmd (user-site installation is not supported).
if platform.system() == "Windows":
library_root_dir_path = Path(__file__).parents[2]
user_site_packages_path = Path(site.getusersitepackages())
if library_root_dir_path.is_relative_to(user_site_packages_path):
scripts_dir = sysconfig.get_path("scripts", "nt_user")
else:
scripts_dir = sysconfig.get_path("scripts")
scripts_dir = sysconfig.get_path("scripts")
khiops_env_path = os.path.join(scripts_dir, "khiops_env.cmd")
if not os.path.exists(khiops_env_path):
raise KhiopsEnvironmentError(
"No 'khiops_env.cmd' found in the current environment. "
"Make sure you have installed Khiops properly. "
"Go to https://khiops.org for more information."
)
# On UNIX, pip places khiops_env in the bin directory,
# On UNIX, pip or uv places khiops_env in the bin directory,
# which is in PATH.
else:
khiops_env_path = self._infer_khiops_env_from_path(
Expand Down Expand Up @@ -1263,7 +1269,7 @@ def _detect_library_installation_incompatibilities(self, library_root_dir_path):
"Go to https://khiops.org for instructions.\n"
)
error_list.append(error)
# 'pip', 'conda-based' or borderline installations
# 'pip', 'uv', 'conda-based' or borderline installations
else:

# ensure a known installer was used otherwise unexpected issues can occur
Expand All @@ -1274,10 +1280,10 @@ def _detect_library_installation_incompatibilities(self, library_root_dir_path):
if caught_warnings is not None:
# caught_warnings contains a list of WarningMessage
warning_list.extend([w.message for w in caught_warnings])
if current_library_installer not in ("conda", "pip"):
if current_library_installer not in ("conda", "pip", "uv"):
warning = (
"Khiops Python library "
"was not installed with 'conda' or 'pip' "
"was not installed with 'conda', 'pip' or 'uv' "
f"but with '{current_library_installer}' installer. "
"This will probably lead to unexpected errors. "
"Go to https://khiops.org for instructions to re-install it.\n"
Expand All @@ -1286,8 +1292,8 @@ def _detect_library_installation_incompatibilities(self, library_root_dir_path):

# we consider only the 'pip' and 'conda-based' installations here
# - 'conda-based' installation (similar to a non-activated virtual env)
# - 'pip' installation under a virtual env
# - User site 'pip' installation (without virtual env)
# - 'pip' or 'uv' installation under a virtual env
# (user-site installation is not supported)
# - system-wide 'pip' installation (without virtual env)...
# (an empty string means a borderline installation was found,
# no further check cannot be performed)
Expand Down Expand Up @@ -1323,7 +1329,7 @@ def _detect_library_installation_incompatibilities(self, library_root_dir_path):
# Under Linux or MacOS a bin/ folder exists
or sys_executable_grand_parent != base_dir_path
):
error = (
message = (
"Khiops Python library installation path "
f"'{library_root_dir_path}' "
"does not match the current python environment "
Expand All @@ -1332,7 +1338,13 @@ def _detect_library_installation_incompatibilities(self, library_root_dir_path):
"to re-install it "
"(preferably in a virtual environment).\n"
)
error_list.append(error)
if installation_method == "uv":
# For the usual usage of 'uv', its virtual environment
# is not explicitly activated, hence we tolerate,
# with a warning, the Python executables mismatch
warning_list.append(message)
else:
error_list.append(message)
else:
sys_executable_path = Path(sys.executable)
# the installation is not within a virtual env
Expand All @@ -1353,28 +1365,6 @@ def _detect_library_installation_incompatibilities(self, library_root_dir_path):
"(preferably in a virtual environment).\n"
)
error_list.append(error)
# fetch the 'User site' site-packages path
# which is already adapted for each OS (Windows, MacOS, Linux)
user_site_packages_path = Path(site.getusersitepackages())
if not library_root_dir_path.is_relative_to(
user_site_packages_path
):
# the library is not installed on the 'User site'
if not library_root_dir_path.is_relative_to(
sys_base_prefix_path
):
# the library is supposed to be installed system-wide,
# but it seems that the location is wrong
error = (
"Khiops Python library installation path "
f"'{library_root_dir_path}' "
"does not match the system-wide Python prefix in "
f"'{sys.base_prefix}'. "
"Go to https://khiops.org for instructions "
"to re-install it "
"(preferably in a virtual environment).\n"
)
error_list.append(error)

return error_list, warning_list

Expand Down
Loading