Why do I have "ModuleNotFoundError: No module named 'scipy.special.cython_special'" when I don't even use cython?
Asked Answered
C

6

9

I used pyinstaller to generate an executable for a python script, and when trying to run the executable I get the error ModuleNotFoundError: No module named 'scipy.special.cython_special'. I'm not sure where this is coming from, or how to fix it. My executable takes in one argument and returns a list. Any help is appreciated!

Constitute answered 25/6, 2020 at 17:57 Comment(2)
Its originating from the scipy package, which is missing the dependency cython_special. I don't know anything about pyinstaller, but my intuition says that the generated executable does not have scipy and it's related dependencies correctly bundled.Shirr
You must be using scipy. scipy uses cython a lot to interface python with compiled packages. You may need to install a fuller 'development' version of scipy (and other packages).Olympias
S
6

I had this error after freezing a program that used scipy version 1.5.0 but I changed the version to 1.4.1 (which I had used with an earlier virtual environment) and the error disappeared.

Selfidentity answered 5/7, 2020 at 5:43 Comment(2)
This worked. Do this and then sort out the next error pyinstaller throws.Gunnysack
@Gunnysack that's totally rubbish I've spent 1 day on pyinstaller errors and I still have more! there should be an official package from python to handle all of thisUnderslung
M
3

I'm getting the same error, and not exactly sure what causes it or why pyinstaller doesn't find that dependency, but you can fix it by adding 'scipy.special.cython_special' to your pyinstaller myapp.spec file like this:

a = Analysis(['/Users/Name/path/to/mystartupfile.py'],
             pathex=['/Users/Name/...'],
             binaries=[],
             datas=[('data')],
             hiddenimports=['scipy.special.cython_special'],
             hookspath=['/Users/Name..../hooks'],
             runtime_hooks=[],
             excludes=['IPython', 'FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter'],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
Mesocarp answered 27/6, 2020 at 21:41 Comment(1)
Thanks for your answer! I added that line to my spec file, but I'm still getting the same error..Constitute
F
2

Add --hidden-import="scipy.special.cython_special" to your pyinstaller command.

Ferromagnetism answered 2/9, 2021 at 10:27 Comment(0)
S
0

I just solved this problem by copying the cython_special.cp37-win_amd64.pyd file from MyEnv>Lib>site-packages>scipy>special into the same directory of the compiled pyinstaller program.

Short answered 30/6, 2020 at 11:8 Comment(0)
L
0

I had the same problem, turns out I was using Python 3.8 which isn't supported by Pyinstaller. Try using 3.7.

Lubra answered 16/7, 2020 at 8:53 Comment(1)
I downgraded from Python 3.8 to Python 3.7, however this didn't help me. I did find that the problem went away after downgrading scipy to version 1.4.1, as per the answer provided by @profTC.Moisture
A
0

I also had this issue.

Downgrading scipy package to 1.4.1 solved the issue as @profTC said.

Alternatively, one can upgrade to PyInstaller 4.0 where they have added a new hook file to deal with this. See: https://pyinstaller.readthedocs.io/en/v4.0/CHANGES.html#hooks

Another solution is to use to directly copy the hook file and include it as an additional hook when building with PyInstaller.

Allister answered 27/10, 2020 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.