解決pyinstaller打包sklearn等庫出現的問題: 提示failed to execute script xxx


 

pyinstaller安裝,簡單打包可以參考:https://blog.csdn.net/qq_40587575/article/details/85076934

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

pyinstaller [參數] [要打包的程序.py]

參數說明:
–icon=圖標路徑
-F 打包成一個exe文件
-w 使用窗口,無控制台
-c 使用控制台,無窗口
-D 創建一個目錄,里面包含exe以及其他一些依賴性文件
pyinstaller -h 來查看參數

重點:

剛開始進行編譯的時候,切忌直接使用:  pyinstaller -F -w demo.py

應該使用:pyinstaller -F -c demo.py  此時打包完成后,點擊exe執行文件,如果有報錯的話,將在控制台顯示。這是,要做好截圖的准備,因為控制台報錯后是一閃而過的。

 報錯信息: No module named 'typedefs'

此時,我們可以看到 importError 的報錯信息,  由於此時找不到typedefs模塊,所以程序直接報 Failed to excute script xxxx

刪除原來的dist、build 文件, spec文件, 在編譯的時候加上: 

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

或者

直接在. spec 文件里的 hiddenimports = [ ] 增加: 如最后的代碼

報錯信息: No module named 'sklearn.neighbors.quad_tree'

報錯信息: No module named 'pywt._extendions._cwt' 

 

匯總上述的問題可以使用命令:

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

程序如果還是會報錯的話, 可以使用相同的方法找出原因,有原因一般就好找答案了。。。。。。。。。。。

參考:

 

1. XGBoost出現的問題解決辦法:

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

2.pywt小波包庫解決方法:

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

3.sklearn解決方法:

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

 

在pyinstaller生成的 .spec文件中修改為:

主要是hiddenimportts  主要都是這一塊出問題,pyinstaller找不到庫在哪里

 # -*- 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----------------------


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM