→ lepenseur: 我明白—add-data 的檔案會放在包裝後目錄下 01/26 01:23
→ lepenseur: 但是,他現在執行exe的錯誤內容,就是去AppData這個目 01/26 01:25
→ lepenseur: 錄讀取資料,而不是從執行檔的目錄下(sys._MEIPASS) 01/26 01:25
→ lepenseur: 抓json 01/26 01:25
→ lepenseur: 所以我才說,他應該要想清楚,部署的平台要怎麼安排這 01/26 01:25
→ lepenseur: 些檔案放哪裡、該怎麼讀 01/26 01:25
→ lepenseur: —add-data可以打包沒錯,但他程式碼是從AppData這邊 01/26 01:26
→ lepenseur: 抓資料,所以會繼續報錯 01/26 01:26
→ lepenseur: 你嘗試把一個檔案只放在AppData,其他目錄不能放,然 01/26 01:28
→ lepenseur: 後嘗試打包、在另一台電腦上執行看看,應該可以重現這 01/26 01:28
→ lepenseur: 個問題 01/26 01:28
→ lepenseur: 你成功打包opencc沒錯,東西也在sys._MAIPASS下沒錯, 01/26 01:30
→ lepenseur: 但你的程式碼就跑去AppData這個目錄抓資料,所以才出現 01/26 01:30
→ lepenseur: 這個錯誤提示 01/26 01:30
→ poototo: 1.add-data檔案【不會】放在包裝後目錄下,是在【exe中】 01/26 09:02
→ poototo: 2.exe執行檔所在目錄 != sys._MEIPASS 01/26 09:02
→ poototo: sys._MEIPASS會指向AppData下的亂數名稱目錄 01/26 09:03
→ poototo: 如原PO的錯誤訊息中的路徑有個 _MEI151842 01/26 09:03
→ poototo: 這是exe每次執行都會當場造的 01/26 09:03
→ poototo: (所以每次執行每次都會更新一次sys._MEIPASS) 01/26 09:03
→ poototo: import相依套件及add-data的檔案都在_MEI151842下解壓 01/26 09:03
→ poototo: user無法【事先部署】這些檔案,是exe自己【當場部署】 01/26 09:04
→ poototo: 原本opencc.py執行時會去讀site-package下opencc下的json 01/26 09:04
→ poototo: 打包exe後,opencc.py的讀取起點會換成sys._MEIPASS 01/26 09:04
→ poototo: 原PO只要將json打包【進exe】,指定正確的解壓path 01/26 09:04
→ poototo: 而非要求使用者電腦中要有一份json或額外安裝相依檔案 01/26 09:04
→ poototo: 使用者只要執行exe就好,不必搞環境部署 01/26 09:04
→ lepenseur: 那請問你要如何指定解壓到該使用者的AppData 呢? 01/26 16:20
→ lepenseur: 你一直忽略錯誤訊息裡面,去AppData讀取資料的這件事, 01/26 16:21
→ lepenseur: 我們一直在雞同鴨講 01/26 16:21
→ lepenseur: 而且真的有需要寫入資料的話,一般都是直接寫安裝精靈 01/26 16:22
→ lepenseur: ,安裝精靈可以做完這些事情,不會讓使用者自己去設定 01/26 16:22
→ lepenseur: 環境 01/26 16:22
→ lepenseur: sys._MAIPASS 我知道如何使用,我也是這樣操作的。但現 01/26 16:24
→ lepenseur: 在的情境是,exe執行時嘗試去AppData讀取資料導致錯誤 01/26 16:24
→ lepenseur: 另外,pyinstaller 解壓執行超慢,一般是小專案才會用 01/26 16:27
→ lepenseur: ,正式的軟體幾G沒辦法等你這樣解壓,建議你了解一下py 01/26 16:27
→ lepenseur: installer產生資料夾的操作 01/26 16:27
→ poototo: add-data就是在指定sys._MEIPASS下的解壓路徑 01/26 16:28
→ poototo: AppData就是在sys._MEIPASS指向的路徑當中 01/26 16:29
→ poototo: 會去讀AppData下的資料就是exe的正常行為 01/26 16:30
推 lepenseur: 抱歉,剛剛去翻文件,我懂你的意思了 01/26 16:31
→ lepenseur: 你說的是pyinstaller -F 下的操作情形 01/26 16:32
→ lepenseur: 我說的是 pyinstaller -D 下的操作情形 01/26 16:32
→ poototo: 你的exe還會在user電腦放很多檔案才能正常執行? 01/26 16:33
→ lepenseur: 所以你才會說解壓檔案到_MAIPASS目錄下 01/26 16:33
→ poototo: 原PO應該是希望打包成 one file的方式 01/26 16:33
→ lepenseur: 我寫的是要部署到客戶端電腦的軟體,基本上是一整個軟 01/26 16:34
→ lepenseur: 體資料夾,檔案大小有時候幾百M或幾G 01/26 16:34
→ lepenseur: 所以都不會使用 onefile 01/26 16:34
→ lepenseur: 長知識了 01/26 16:34
→ lepenseur: 功能稍微多一點,每次開啟onefile解壓縮就要等超久 01/26 16:36
→ lepenseur: 感謝poo大,讓我更了解onefile的運作機制 01/26 16:36
→ poototo: 剛看原PO是用 -F,但我也在想是否可以不要打包python套件 01/26 16:40
→ poototo: import一堆,exe常100M上下,然後執行又解壓套件出來 01/26 16:40
推 lepenseur: 原ok原本加上—add-data還是掛,所以我以為他路徑設定 01/26 16:42
→ lepenseur: 錯,他後面也沒出來回覆 01/26 16:42
→ lepenseur: 可能問題已經解決了 01/26 16:42
推 lepenseur: 不打包python套件可能比較難,就是需要用到才import的 01/26 16:47
→ lepenseur: 啊XD 01/26 16:47
→ lepenseur: 我還是覺得onedir的方式比較好用,加上安裝精靈,資料 01/26 16:48
→ lepenseur: 夾安裝在C槽,桌面建立一個捷徑,方便實用 01/26 16:48