简体   繁体   中英

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?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM