pyinstaller exe error No module named 'sklearn.utils._typedefs'

### Describe the bug
in my code 
 from sklearn.ensemble import RandomForestClassifier

When I use pyinstaller to convert my .py file to exe it work on scikit-learn version 0.24.2 but not 1.0.2

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



### Steps/Code to Reproduce

#Create a myprg.py file with following code
from sklearn.ensemble import RandomForestClassifier

# then run pyinstaller in command prompt
pyinstaller --hidden-import="sklearn.utils._cython_blas" --hidden-import="sklearn.neighbors.typedefs" --hidden-import="sklearn.neighbors.quad_tree" --hidden-import="sklearn.tree._utils" --hiddenimport win32timezone -F myprg.py

# run exefile
myprg.exe





### Expected Results
on error

### Actual Results

File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "sklearn\ensemble\__init__.py", line 5, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "sklearn\ensemble\_base.py", line 18, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "sklearn\tree\__init__.py", line 6, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "sklearn\tree\_classes.py", line 41, in <module>
  File "sklearn\tree\_criterion.pyx", line 1, in init sklearn.tree._criterion
  File "sklearn\tree\_splitter.pyx", line 1, in init sklearn.tree._splitter
  File "sklearn\tree\_tree.pyx", line 1, in init sklearn.tree._tree
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "sklearn\neighbors\__init__.py", line 6, in <module>
  File "sklearn\neighbors\_ball_tree.pyx", line 1, in init sklearn.neighbors._ball_tree
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "sklearn\metrics\__init__.py", line 39, in <module>
  File "sklearn\metrics\_dist_metrics.pyx", line 31, in init sklearn.metrics._dist_metrics
ModuleNotFoundError: No module named 'sklearn.utils._typedefs'
### Versions

```shell
1.0.2
```

COMMENT:
Your solution work. Thank you very much to solve my question.
    On Friday, April 29, 2022, 10:15:57 AM EDT, Thomas J. Fan ***@***.***> wrote:  
 
 


At a glance, the hidden import paths need to be specified. In this case the following worked for me (with sklearn 1.0.2)
pyinstaller --hidden-import="sklearn.utils._typedefs" \
            --hidden-import="sklearn.neighbors._partition_nodes" \
            -F myprg.py
Note these paths may change from version to version. In v0.22, scikit-learn deprecated a lot of modules such as sklearn.neighbors.quad_tree and made them private, so they are not available anymore in 1.0.

I am closing this issue, because it is about using pyinstaller and not a bug with scikit-learn itself.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>

Labels: Question