ModuleNotFoundError: No module named 'sklearn.utils._typedefs'

When I try to execute the exe file made my pyinstaller I got the error message No module named 'sklearn.utils._typedefs'. I use from sklearn.ensemble import RandomForestClassifier in my python code.

I did use the --hidden-import and solve the problem before but when I try use the different version's python it didn't works

The command I use is pyinstaller --hidden-import="sklearn.utils._cython_blas" --hidden-import="sklearn.neighbors.typedefs" --hidden-import="sklearn.neighbors.quad_tree" --hidden-import="sklearn.tree._utils" -F myprgname.py

The old setting works

Python 3.6.8 pyinstaller==4.6 pyinstaller-hooks-contrib==2021.3 python-dateutil==2.8.2 pytz==2021.3 scikit-learn==0.24.2

The new setting (got error message above)

Python 3.7.8 pyinstaller==5.0.1 pyinstaller-hooks-contrib==2022.4 python-dateutil==2.8.2 pytz==2022.1 scikit-learn==1.0.2

any suggestion is appreciated.

1 answer

  • answered 2022-04-29 15:00 Brian

    Had the same issue today, I resolved it by adding news hidden imports :

    --hidden-import="sklearn.utils._typedefs"
    

    This one may be sufficient for your issue, but for me, I had to add also :

    --hidden-import="sklearn.neighbors._partition_nodes"
    

    Here is the full command that I used :

    pyinstaller --hidden-import="sklearn.utils._cython_blas" --hidden-import="sklearn.neighbors.typedefs" --hidden-import="sklearn.neighbors.quad_tree" --hidden-import="sklearn.tree._utils" --hidden-import="sklearn.neighbors._typedefs" --hidden-import="sklearn.utils._typedefs" --hidden-import="sklearn.neighbors._partition_nodes" --onefile MyPythonScript.pyw
    

    My environment :

    Python 3.9.12
    Pyinstaller 5.0.1
    pyinstaller-hooks-contrib==2022.4
    python-dateutil==2.8.2
    scikit-learn==1.0.2
    pytz == none
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum