Skip to content

IronPython.Runtime.Exceptions.ImportException:“No module named 'sklearn.linear_model._base'” #1927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
abiaogo opened this issue Mar 14, 2025 · 4 comments

Comments

@abiaogo
Copy link

abiaogo commented Mar 14, 2025

Environments:
Windows11, Visual Studio Version: 17.13.2 ;
IronPython version: 3.4.2; scikit-learn Version: 1.6.1 ;

Q1: Dose IronPython 3.4.2 support scikit-learn? is yes, how to solve this problem.
Q2: I want to load a line-regression model to c#, how to achieve this if IronPython 3.4.2 don't support scikit-learn.

@abiaogo
Copy link
Author

abiaogo commented Mar 14, 2025

Use Python 3.13.2 and scikit-learn 1.6.1 to generate the line-regression module and save it by "pickle.dump(model, file)"
Use Python 3.13.2 can load the model successfully by "model = pickle.load(file)"
The problem happened when I tried to load the model in .net8.0 use IronPython version: 3.4.2.

//C# code
using IronPython.Hosting;
class Program
{
static void Main(string[] args)
{
var engine = Python.CreateEngine();
engine.Execute(code);
dynamic py = engine.ExecuteFile("sklearn_line_load.py");
}
}

##sklearn_line_load.py
import pickle
with open('linear_model.pkl', 'rb') as file:
model = pickle.load(file)
def predict_price(data):
result = model.predict([data])
result = round(result[0])
return result

@Lamparter
Copy link
Contributor

scikit-learn doesn't support Python 3.4.x. You will need to use 0.20 or earlier of scikit-learn to use it in IronPython.

@BCSharp
Copy link
Member

BCSharp commented Mar 14, 2025

scikit-learn depends on numpy. numpy is an extension package for Python and is incompatible with IronPython.

So scikit-learn (any version) does not work currently with IronPython 3. I suggest you look at Python for .NET whether it satisfies your needs.

@BCSharp BCSharp closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2025
@abiaogo
Copy link
Author

abiaogo commented Mar 14, 2025

thank you buddy. it's clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants