2025, Oct 16 19:00

How to resolve Poetry dependency conflicts between scikit-learn and imbalanced-learn caused by sklearn-compat

Poetry fails resolving scikit-learn and imbalanced-learn due to sklearn-compat. See why on Python 3.13 and fix: pin scikit-learn below 1.7 or install from Git

When adding scikit-learn and imbalanced-learn to a fresh Poetry project, the dependency resolver can fail with a version conflict. The core of the issue is a constraint introduced by sklearn-compat, which imbalanced-learn relies on. Below is a concise walkthrough of what happens, why it happens, and how to move forward without derailing your setup.

Reproducing the issue

Start with a minimal project configuration targeting Python 3.13. Poetry version is 2.1.4.

# File pyproject.toml

[project]
name = "ml-kit"
version = "0.1.0"
description = ""
authors = [
    {name = "", email = ""}
]
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
]

Attempt to add the two packages with Poetry:

ubuntu@ubuntu:~/ml-kit$ poetry add scikit-learn imbalanced-learn
Creating virtualenv ml-kit in /home/ubuntu/ml-kit/.venv
Using version ^1.7.1 for scikit-learn
Using version ^0.13.0 for imbalanced-learn

Updating dependencies
Resolving dependencies... (0.4s)

Because no versions of sklearn-compat match >0.1,<0.1.1 || >0.1.1,<0.1.2 || >0.1.2,<0.1.3 || >0.1.3,<1
 and sklearn-compat (0.1.0) depends on scikit-learn (>1.2,<1.7), sklearn-compat (>=0.1,<0.1.1 || >0.1.1,<0.1.2 || >0.1.2,<0.1.3 || >0.1.3,<1) requires scikit-learn (>1.2,<1.7).
And because sklearn-compat (0.1.1) depends on scikit-learn (>=1.2,<1.7), sklearn-compat (>=0.1,<0.1.2 || >0.1.2,<0.1.3 || >0.1.3,<1) requires scikit-learn (>=1.2,<1.7).
And because sklearn-compat (0.1.2) depends on scikit-learn (>=1.2,<1.7)
 and sklearn-compat (0.1.3) depends on scikit-learn (>=1.2,<1.7), sklearn-compat (>=0.1,<1) requires scikit-learn (>=1.2,<1.7).
Because no versions of imbalanced-learn match >0.13.0,<0.14.0
 and imbalanced-learn (0.13.0) depends on sklearn-compat (>=0.1,<1), imbalanced-learn (>=0.13.0,<0.14.0) requires sklearn-compat (>=0.1,<1).
Thus, imbalanced-learn (>=0.13.0,<0.14.0) requires scikit-learn (>=1.2,<1.7).
So, because ml-kit depends on both scikit-learn (^1.7.1) and imbalanced-learn (^0.13.0), version solving failed.
ubuntu@ubuntu:~/ml-kit$

What actually breaks

The failure is caused by transitive constraints. imbalanced-learn uses sklearn-compat, and sklearn-compat requires scikit-learn to be lower than 1.7. When Poetry picks scikit-learn ^1.7.1 for your project, it contradicts the upper bound enforced by sklearn-compat. The resolver highlights this chain precisely: imbalanced-learn 0.13.0 depends on sklearn-compat (>=0.1,<1), and all available sklearn-compat 0.1.x releases require scikit-learn >=1.2,<1.7.

Two practical ways forward

The first path is to align scikit-learn with the constraint that comes through sklearn-compat. Pin scikit-learn below 1.7 and let Poetry solve the rest. This keeps everything on released, packaged versions and stays strictly within published constraints.

poetry add 'scikit-learn<1.7' imbalanced-learn

The second path is to consume imbalanced-learn directly from its repository. The following discussion in the project’s tracker provides the background:

Still don't support scikit-learn 1.70? · Issue #1141 · scikit-learn-contrib/imbalanced-learn

Installing from the repo with pip has been tested and it pulls scikit-learn 1.7.1 automatically:

pip install git+https://github.com/scikit-learn-contrib/imbalanced-learn.git

Using Poetry with the same Git URL may vary. The command below can produce the message “Unable to create package with no name”:

poetry add git+https://github.com/scikit-learn-contrib/imbalanced-learn.git

At the same time, there is a report that using this URL works. If the Git-based installation is acceptable in your workflow, this approach can unblock you with newer scikit-learn.

Fixed example

If you choose to stay on released packages, pin scikit-learn below 1.7. Poetry will resolve cleanly:

ubuntu@ubuntu:~/ml-kit$ poetry add 'scikit-learn<1.7' imbalanced-learn

This results in a pyproject that effectively constrains scikit-learn to a compatible range while keeping imbalanced-learn at 0.13.x.

Why this matters

Bindings like sklearn-compat are a common bridge during dependency transitions. They protect downstream libraries from breaking changes but can also hold back the top-level version you get when you let the resolver pick the latest. Understanding which package enforces the upper bound helps you decide whether to accept an older, stable dependency set or switch to a Git-based install when a project is catching up to a new major or minor release.

Takeaways

When Poetry fails to resolve with scikit-learn and imbalanced-learn, read the resolver output closely. If sklearn-compat appears in the chain and caps scikit-learn below 1.7, pin scikit-learn<1.7 and proceed, or install imbalanced-learn directly from its repository if that fits your policy. Keep an eye on the linked issue to know when packaged releases lift the constraint and you can return to the latest scikit-learn without extra steps.

The article is based on a question from StackOverflow by winter and an answer by furas.