Solve the problem that pyinstaller packages sklearn and other libraries: prompt failed to execute script xxx

 

pyinstaller installation, simple packaging can refer to: https://blog.csdn.net/qq_40587575/article/details/85076934

------------------------------------------------------------------------------------------------------------------------------------------------------------------

pyinstaller [parameter] [program to be packaged.py]

Parameter description:
-icon = Icon path-
F packaged into an exe file-
w Use window, no console-
c Use console, no window-
D Create a directory containing exe and some other dependent files
pyinstaller -h View parameters

Key points:

When you first start to compile, do not use it directly: pyinstaller -F -w demo.py

Should use: pyinstaller -F -c demo.py At this point, after packaging is completed, click exe to execute the file. If there is an error, it will be displayed on the console. This is to prepare for screenshots, because the console flashed after an error.

 Error message: No module named 'typedefs'

At this time, we can see the error message of importError. Since the typedefs module cannot be found at this time, the program directly reports Failed to excute script xxxx

Delete the original dist, build file, spec file, add: 

pyinstaller -F -c QTimerTest.py --hidden-import sklearn.neighbors.typedefs

or

Hiddenimports = [] added directly in the .spec file: as the last code

Error message: No module named 'sklearn.neighbors.quad_tree'

Error message: No module named 'pywt._extendions._cwt' 

 

To summarize the above issues, you can use the command:

pyinstaller -F -c QTimerTest.py --hidden-import sklearn.neighbors.typedefs --hidden-import sklearn.neighbors.quad_tree --hidden-import pywt._extensions._cwt --add-data=xgboost;xgboost

If the program still reports an error, you can use the same method to find out the reason. If you have a reason, you can usually find the answer. . . . . . . . . . .

reference:

 

1. The solution to the problem of XGBoost:

https://my.oschina.net/u/1241965/blog/2997992

2.pywt wavelet package library solution:

https://stackoverflow.com/questions/41998403/pyinstaller-importerror-on-pywt-ctw-module

3. Sklearn solution:

https://www.smwenku.com/a/5b86bb8a2b71775d1cd5c2d8/zh-cn/

https://stackoverflow.com/questions/31774906/why-do-i-get-an-importerror-when-building-a-exe-with-pyinstaller

http://www.voidcn.com/article/p-nqtjgive-bms.html

 

In the .spec file generated by pyinstaller, modify to:

It ’s mainly hiddenimportts. It ’s mainly because of this problem, pyinstaller ca n’t find where the library is.

 # -*- mode: python -*-

block_cipher = None


a = Analysis(['MyPythonApplication.py'],
             pathex=['..\\ApplicationFolder'],
             binaries=[],
             datas=[],
             hiddenimports=['cython', 'sklearn', 'sklearn.ensemble', 'sklearn.neighbors.typedefs', 'sklearn.neighbors.quad_tree', 'sklearn.tree._utils'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='ExeFileName',             
          debug=False,
          strip=False,
          upx=False,
          console=False )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='ApplicationName')

                                   

 

  -----------------done----------------------

Guess you like

Origin www.cnblogs.com/junge-mike/p/12761311.html