1. 程式人生 > 程式設計 >解決pyinstaller打包執行程式時出現缺少plotly庫問題

解決pyinstaller打包執行程式時出現缺少plotly庫問題

用pyinstaller打包tkinter程式,打包後執行exe是報如下錯誤:

解決pyinstaller打包執行程式時出現缺少plotly庫問題

搜尋一陣發現是pyinstaller在打包的時候(StartRun.py我要打包的主程式檔案)可能會漏掉一些三方庫,就在打包的時候加上三方庫的絕對路徑:

pyinstaller StartRun.py -F -p C:\Python36\Lib\site-packages

發現打包完之後還是會報以上問題,繼續搜尋後用新增hook檔案的方式可以解決(徹底解決了我的問題),修改方法:

1.找到C:\Python36\Lib\site-packages\PyInstaller\hooks,長這樣:

解決pyinstaller打包執行程式時出現缺少plotly庫問題

2.需要在這裡新建一個類似的檔案hook-plotly.py,檔案內容如下:

from PyInstaller.utils.hooks import collect_data_files
 
datas = collect_data_files('plotly')

3.然後重新打包,打包的時候切記把StartRun.py的同級目錄下StartRun.spec檔案刪除(在打包的時候會自動生成,如果不刪除之前不成功的內容還是快取在的),打包過程中會看到添加了plotly庫:

解決pyinstaller打包執行程式時出現缺少plotly庫問題

pyinstaller打包常用命令:

-F 指定打包後只生成一個exe格式的檔案
-D –onedir 建立一個目錄,包含exe檔案,但會依賴很多檔案(預設選項)
-c –console,–nowindowed 使用控制檯,無介面(預設)

-w –windowed,–noconsole 使用視窗,無控制檯

-i改變生成程式的icon圖示

pyinstaller打包plotly後無法正常執行的問題

在使用pyinstaller打包帶有plotly的程式後,在執行程式時會出現如下反饋

"c:\users*\appdata\local\continuum\anaconda3\envs\py34\lib\site-p ackages\PyInstaller\loader\pyimod03_importers.py",line 474,in get_data
with open(path,'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory:

'H:\Python\Commodity_M AI_Trade_List\Code\dist\comdty_runtime\plotly\package_data\default-schema. json'
Failed to execute script comdty_runtime

這是由於pyinstaller現在還無法相容plotly的原因所造成的,解決方法如下:
1.在打包時不要選擇使用-F打包成單個檔案
2.在打包完後,從anaconda目錄下複製plotly資料夾(作者的位置是E:Anaconda3\Lib\site-packages\plotly)到打包完成的資料夾中(作者的位置是D:\Anaconda Library\XXXX專案\dist{exe名字資料夾}\)。

複製完成後,就可以順利使用exe檔案啦~

到此這篇關於解決pyinstaller打包執行程式時出現缺少plotly庫問題的文章就介紹到這了,更多相關pyinstaller打包執行plotly出錯內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!