When trying to build a Python executable with Pyinstaller, fails to find an existing scipy module

StackOverflow https://stackoverflow.com/questions/18791482

  •  28-06-2022
  •  | 
  •  

Frage

I have a build script for one of my established Python applications that uses Pyinstaller. This script has been working fine for over a year. Then today, I added to one of the source files for this application the line

import scipy.stats

because I want to use scipy.stats.linregress. This now causes the build script to crash with a long error traceback (apparently going back through a sequence of modules that import each other) ending with

  File "C:\Users\462974\Documents\Local Sandbox\fof\TRUNK\programs\CDFParsing\build\pyi.win32\CDFGUI\outPYZ1.pyz/scipy.sparse.csgraph", line 148, in <module>
  File "C:\Python27\pyinstaller-1.5\iu.py", line 436, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "C:\Python27\pyinstaller-1.5\iu.py", line 495, in doimport
    mod = importfunc(nm)
  File "C:\Python27\pyinstaller-1.5\iu.py", line 297, in getmod
    mod = owner.getmod(nm)
  File "C:\Python27\pyinstaller-1.5\archive.py", line 468, in getmod
    return iu.DirOwner.getmod(self, self.prefix+'.'+nm)
  File "C:\Python27\pyinstaller-1.5\iu.py", line 109, in getmod
    mod = imp.load_module(nm, fp, attempt, (ext, mode, typ))
  File "_shortest_path.pyx", line 18, in init scipy.sparse.csgraph._shortest_path (scipy\sparse\csgraph\_shortest_path.c:14224)
  File "C:\Python27\pyinstaller-1.5\iu.py", line 455, in importHook
    raise ImportError, "No module named %s" % fqname
ImportError: No module named scipy.sparse.csgraph._validation

This is puzzling because the module located at C:\Python27\Lib\site-packages\scipy\sparse\csgraph_validation.py very much exists. Why did adding scipy to my build break it (importing numpy works just fine), could it be failing to find it?

War es hilfreich?

Lösung

Not entirely sure why, but including the following definition in my code after the import statement fixed it:

def fix_dependencies():
    from scipy.sparse.csgraph import _validation
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top