I am trying to install scikit-learn
and imbalanced-learn
for ML project using poetry
.
# File pyproject.toml
[project]
name = "hello"
version = "0.1.0"
description = ""
authors = [
{name = "",email = ""}
]
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
]
python (version 3.13.6)
Poetry (version 2.1.4)
But, Getting error as below:
ubuntu@ubuntu:~/hello$ poetry add scikit-learn imbalanced-learn
Creating virtualenv hello in /home/ubuntu/hello/.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 hello depends on both scikit-learn (^1.7.1) and imbalanced-learn (^0.13.0), version solving failed.
ubuntu@ubuntu:~/hello$
please help.
It seems imbalanced-learn
uses sklearn-compat
which needs scikit-learn < 1.7
So if you can work with older version then you may install with < 1.7
using:
poetry add 'scikit-learn<1.7' imbalanced-learn
On imbalance-learn
repo I also found:
Still don't support scikit-learn 1.70? · Issue #1141 · scikit-learn-contrib/imbalanced-learn
One answer suggests to install imbalance-learn
directly from repo
and it should work with newer scikit-learn
.
I tested it only with pip
pip install git+https://github.com/scikit-learn-contrib/imbalanced-learn.git
and I see it automatically installs scikit-learn 1.7.1
Command
poetry add git+https://github.com/scikit-learn-contrib/imbalanced-learn.git
gives me
Unable to create package with no name
so maybe someone else will have experience to install it directly with poetry