7

My wxpython application compiled fine with pyinstaller, until some functionality, based on the from scipy.optimize import leastsq statement was added.

How do I fix this?

Clausen
  • 694
  • 8
  • 19

1 Answers1

14

First time you run the command pyinstaller myscript.py in the cmd, a myscript.spec file will be created (or you can create it manually). This file let you specify hidden imports, and I found (by a long and tedious trial-error process) that the following hidden imports did the trick:

'scipy.special._ufuncs_cxx'
'scipy.linalg.cython_blas'
'scipy.linalg.cython_lapack'
'scipy.integrate'
'scipy.integrate.quadrature'
'scipy.integrate.odepack'
'scipy.integrate._odepack'
'scipy.integrate.quadpack'
'scipy.integrate._quadpack'
'scipy.integrate._ode'
'scipy.integrate.vode'
'scipy.integrate._dop'
'scipy.integrate.lsoda'

These should probably be linked through hooks, but I could not get my head around how, so this is the "quick&dirty" way.

Now you execute pyinstaller myscript.spec.

My full file looked along these lines:

# -*- mode: python -*-
a = Analysis(['myscript.py'],
             pathex=['C:\\SourceCode'],
             hiddenimports=['scipy.special._ufuncs_cxx',
                            'scipy.linalg.cython_blas',
                            'scipy.linalg.cython_lapack',
                            'scipy.integrate',
                            'scipy.integrate.quadrature',
                            'scipy.integrate.odepack',
                            'scipy.integrate._odepack',
                            'scipy.integrate.quadpack',
                            'scipy.integrate._quadpack',
                            'scipy.integrate._ode',
                            'scipy.integrate.vode',
                            'scipy.integrate._dop',
                            'scipy.integrate.lsoda'],
             hookspath=None,
             runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='myscript.exe',
          debug=False,
          strip=None,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=None,
               upx=True,
               name='myscript')
Clausen
  • 694
  • 8
  • 19
  • I am having a similar issue when trying to import "scipy.special" (to use scipy.special._ufuncs). Could you slightly elaborate on your algorithm to find the hidden imports needed; "by a long and tedious trial-error process" ? – Rboreal_Frippery May 01 '19 at 16:51
  • 1
    My post was delete by [ChrisF♦](https://stackoverflow.com/users/59303/chrisf) , hope this link helps anyone in search of answer for this in detail [Pyinstaller created exe file can not load a keras nn model](https://stackoverflow.com/questions/45830206/pyinstaller-created-exe-file-can-not-load-a-keras-nn-model#answer-45842864) – Santhosh Dhaipule Chandrakanth Jul 18 '19 at 13:46