Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use pyinstaller with hidden imports for scipy.optimize leastsq

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?

like image 371
Clausen Avatar asked Jan 28 '16 11:01

Clausen


1 Answers

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')
like image 98
Clausen Avatar answered Sep 16 '22 18:09

Clausen