Python寫好的執行要直接轉成exe檔在其他沒裝Python直接運行,可是轉出來的exe檔都好大,幾KB的py檔轉成exe變成幾百MB。
原來是因為之前是用Anaconda裝好環 境的,裡面有一大堆套件,在轉換時,也一直被塞進去了。
要解決這個問題,就是建一個新的虛擬環境,裝上所需的套件,再進行轉換,exe檔就變成幾十MB而已。
可以參考下面網站,說的非常清楚。
https://inf.news/zh-hant/technique/0abeedacd79bf29153e82893d9a0e280.html
Converting a Python script into an executable (.exe) file is a convenient way to run the program on systems without Python installed. However, the resulting .exe files tend to be quite large, often several hundred megabytes, even for scripts that are just a few kilobytes in size.
The reason behind this issue is that if you previously developed your code within an Anaconda environment, it likely included a multitude of packages and dependencies. During the conversion process, these dependencies are also bundled into the executable, contributing to its substantial size increase.
To address this problem, a solution involves creating a new virtual environment, installing only the necessary packages, and then proceeding with the conversion process. This approach results in executable files that are only a few tens of megabytes in size.
For a detailed guide on how to accomplish this, you can refer to the following website:
https://inf.news/zh-hant/technique/0abeedacd79bf29153e82893d9a0e280.html