How to use pyinstaller with hidden import for scipy.optimize lesssq

The wxpython application was compiled using pyinstaller until some functionality based on the from scipy.optimize import leastsq instruction was added.

How to fix it?

+6
source share
2 answers

The first time you run the pyinstaller myscript.py in cmd, the myscript.spec file will be created (or you can create it manually). This file allows you to specify a hidden import, and I discovered (through long and tedious trial error processes) that the following hidden import 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' 

This is probably due to the hooks, but I could not figure out how to do this, so this is a β€œquick and dirty” way.

You are now executing pyinstaller myscript.spec .

My complete file looked like this:

 # -*- 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') 
+10
source

Hope this helps anyone having

 'ModuleNotFoundError: No module named 'sklearn.*'' 'ModuleNotFoundError: No module named 'h5py.*'' 'ModuleNotFoundError: No module named 'sklearn.*'' 

During or after the pyinstaller build

Example if you get an error for h5py

After running pyinstaller myscript.py myscript.spec generated

myscript.spec inside myscript.spec

 # -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis(['myscript.py'], binaries=None, datas=[], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None) # ... rest of a file untouched 

add

 from PyInstaller.utils.hooks import collect_submodules hidden_imports = collect_submodules('h5py') 

and

 hiddenimports=hidden_imports, 

Like this

 # -*- mode: python ; coding: utf-8 -*- block_cipher = None from PyInstaller.utils.hooks import collect_submodules hidden_imports = collect_submodules('h5py') a = Analysis(['myscript.py'], binaries=None, datas=[], hiddenimports=hidden_imports, hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None) # ... rest of a file untouched 

Then save myscript.spec and run the pyinstaller myscript.spec

Credit 9dogs Pyinstaller created EXE file cannot load model Keras NN

0
source

Source: https://habr.com/ru/post/1241709/


All Articles