Repository: pyinstaller/pyinstaller

Issue:
scipy 1.6.0: No module named 'scipy.spatial.transform._rotation_groups'
## Description of the issue

cannot compile simple file when installed scipy version 1.6.0

## Context information (for bug reports)

* Output of `pyinstaller --version`: ```4.0 or develop```
* Version of Python: 3.7
* Platform: windows
* preinstall specific version of scipy `pip install scipy==1.6.0`


### Make sure [everything is packaged correctly](https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs#make-sure-everything-is-packaged-correctly)

  * [x] start with clean installation
  * [x] use the latest development version
  * [x] Run your frozen program **from a command window (shell)** — instead of double-clicking on it
  * [x] Package your program in **--onedir mode**
  * [x] Package **without UPX**, say: use the option `--noupx` or set `upx=False` in your .spec-file
  * [x] Repackage you application in **verbose/debug mode**. For this, pass the option `--debug` to `pyi-makespec` or `pyinstaller` or use `EXE(..., debug=1, ...)` in your .spec file.


### A minimal example program which shows the error

```python
from sklearn.mixture import GaussianMixture
print('ok')
```

### Stacktrace / full error message

```sh
λ .\dist\test\test.exe
Traceback (most recent call last):
  File "test.py", line 1, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "sklearn\__init__.py", line 80, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "sklearn\base.py", line 21, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "sklearn\utils\__init__.py", line 23, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "sklearn\utils\class_weight.py", line 7, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "sklearn\utils\validation.py", line 25, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "sklearn\utils\fixes.py", line 18, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "scipy\stats\__init__.py", line 391, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "scipy\stats\stats.py", line 174, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "scipy\spatial\__init__.py", line 107, in <module>
  File "c:\dev\project\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "scipy\spatial\transform\__init__.py", line 19, in <module>
  File "rotation.pyx", line 5, in init scipy.spatial.transform.rotation
ModuleNotFoundError: No module named 'scipy.spatial.transform._rotation_groups'
[5660] Failed to execute script test

```



### Reason of a bug

scipy has one script cythonized from .py to .pyx:
https://github.com/scipy/scipy/pull/12286


### Solution

add new hook:
`hook-scipy.spatial.transform.py`

contents:
```python
from PyInstaller.utils.hooks import is_module_satisfies

if is_module_satisfies("scipy >= 1.6.0"):
    hiddenimports = ['scipy.spatial.transform._rotation_groups']

```



BTW it is similar to the bug submitted half a year ago, also connected with converting python to cython: https://github.com/pyinstaller/pyinstaller/pull/4981 - is there an automatic way to find such files?


Discussion:
Duplicate of #5440.

Resolving patch:
diff --git a/PyInstaller/hooks/hook-scipy.spatial.transform.rotation.py b/PyInstaller/hooks/hook-scipy.spatial.transform.rotation.py
new file mode 100644
--- /dev/null
+++ b/PyInstaller/hooks/hook-scipy.spatial.transform.rotation.py
@@ -0,0 +1,17 @@
+#-----------------------------------------------------------------------------
+# Copyright (c) 2021, PyInstaller Development Team.
+#
+# Distributed under the terms of the GNU General Public License (version 2
+# or later) with exception for distributing the bootloader.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#
+# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
+#-----------------------------------------------------------------------------
+
+from PyInstaller.utils.hooks import is_module_satisfies
+
+# As of scipy 1.6.0, scipy.spatial.transform.rotation is cython-compiled,
+# so we fail to automatically pick up its imports
+if is_module_satisfies("scipy >= 1.6.0"):
+    hiddenimports = ['scipy.spatial.transform._rotation_groups']


Test patch: