問題描述
我嘗試使用 PyInstaller 3.2.1 創建一個 exe 文件,出于測試目的,我嘗試為以下代碼制作一個 exe:
I try to create an exe file using PyInstaller 3.2.1, for test purpose I tried to make an exe for following code:
import pandas as pd
print('hello world')
經過相當長的時間(15 分鐘以上),我完成了 620 MB 的 dist 文件夾并構建了 - 150 MB.我使用 Python 3.5.2 |Anaconda custom(64 位)在 Windows 上工作.可能值得注意的是,在 dist 文件夾中,mkl 文件負責將近 300 MB.我使用pyinstaller.exe foo.py"運行 pyinstaller.我嘗試使用 --exclude-module 排除一些依賴項,但最終還是得到了巨大的文件.我使用 onefile 還是 onedir 沒有任何區別.
After considerable amount of time (15mins +) I finished with dist folder as big as 620 MB and build - 150 MB. I work on Windows using Python 3.5.2 |Anaconda custom (64-bit). Might be worth noting that in dist folder mkl files are responsible for almost 300 MB. I run pyinstaller using 'pyinstaller.exe foo.py'. I tried using --exclude-module to exclude some dependencies, still ended up with huge files. Whether I use onefile or onedir doesn't make any difference.
我知道 exe 必須包含一些重要文件,但大小接近 1 GB 是否正常?如有必要,我可以提供警告日志或任何有助于解決問題的內容.
I am aware that exe must contain some important files but is it normal to be as big as almost 1 GB? I can provide warning log if necessary or anything that could be helpful to solve the matter.
附:同時,我的同事從相同的示例腳本創建了一個 exe,最終不到 100 MB,不同之處在于他沒有使用 anaconda.會是這樣嗎?
P.S. In parallel my coworker created an exe from same sample script and ended up with less than 100 MB, difference is he is not using anaconda. Could that be the matter?
任何幫助將不勝感激.
推薦答案
PyInstaller 從 conda 包創建大可執行文件,從 pip 包創建小可執行文件.從這個簡單的python代碼:
PyInstaller create the big executable from the conda packages and the small executable from the pip packages. From this simple python code:
from pandas import DataFrame as df
print('h')
我通過 conda 包獲得了 203MB 的可執行文件,通過 pip 包獲得了 30MB 的可執行文件.但是 conda 是純 virtualenv 的一個很好的替代品.我可以使用 conda 和 Jupyter 進行開發,創建一些 mycode.py(我可以將 jupyter notebook 作為 py 文件下載到 myfolder 中).但我的最終解決方案是下一個:如果沒有,請安裝 Miniconda 并從 Windows 開始菜單打開 Anaconda Prompt;
I obtain the 203MB executable by the conda packages and the 30MB executable by the pip packages. But conda is the nice replacement of the pure virtualenv. I can develop with conda and Jupyter, create some mycode.py (I can download jupyter notebook as py-file in myfolder). But my final solution is next: If you do not have it, install Miniconda and from the Windows Start Menu open Anaconda Prompt;
cd myfolder
conda create -n exe python=3
activate exe
pip install pandas pyinstaller pypiwin32
echo hiddenimports = ['pandas._libs.tslibs.timedeltas'] > %CONDA_PREFIX%Libsite-packagesPyInstallerhookshook-pandas.py
pyinstaller -F mycode.py
在我創建新環境exe"的地方,pypiwin32 需要 pyinstaller 但不會自動安裝,hook-pandas.py 需要用 pandas 編譯.此外,導入子模塊并不能幫助我優化可執行文件的大小.所以我不需要這個東西:
Where I create new environment 'exe', pypiwin32 need for pyinstaller but is not installed automaticaly, hook-pandas.py need for compile with pandas. Also, import submodules do not help me optimize the size of the executable file. So I do not need this thing:
from pandas import DataFrame as df
但我可以使用通常的代碼:
but I can just use the usual code:
import pandas as pd
此外,在路徑中使用國家字母可能會出現一些錯誤,因此開發工具的英文用戶帳戶很好.
Also, some errors are possible along using the national letters in paths, so it is nice the english user account for development tools.
這篇關于帶有 Pandas 的 PyInstaller 創建超過 500 MB 的 exe的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!