問(wèn)題描述
我一直在嘗試在 Windows 10 中使用 pyinstaller 構(gòu)建 .exe 文件.它有效,但 exe 文件的大小約為 212 MB,即使使用 venv 也是如此(如 這里).我想這可能是因?yàn)槲艺谑褂?anaconda 的 python!
I have been trying to build .exe file using pyinstaller in windows 10. It worked, but the size of the exe file is ~212 MB, even by using a venv (as in here). I thought it might be because I am using python by anaconda!
然后我安裝了一個(gè)單獨(dú)的 Python 版本,所以不要使用 anaconda!但它不起作用(仍然是大文件).
Then I installed a separate version of Python so not to use anaconda! But it did not work (still large file).
然后我卸載了 anaconda 進(jìn)行測(cè)試.Pyinstaller 仍在嘗試訪問(wèn)C:Program Filesanaconda3python.exe"中的 Python(此錯(cuò)誤:C:Program Filesanaconda3python.exe"中沒(méi)有 Python).但是我已經(jīng)刪除了所有到 anaconda 的路徑.可能它一直試圖到達(dá) anaconda,這就是為什么我沒(méi)有成功構(gòu)建一個(gè)小尺寸的 .exe 文件.
Then I uninstalled anaconda to test it. Pyinstaller is still trying to access Python in 'C:Program Filesanaconda3python.exe' (this error: No Python at 'C:Program Filesanaconda3python.exe'). However I have removed all path to anaconda. Probably it has always tried to reach anaconda, and this is why I haven't been successful to build a small size .exe file.
如何清楚地指明 pyinstaller 和 python 的路徑?
How can I clearly indicate paths for pyinstaller and python?
推薦答案
終于,經(jīng)過(guò)大量研究,可以解決我的問(wèn)題:
Finally, after a lot of researching, could solve my problem:
- 從我的電腦上卸載了所有的 python 和 anaconda
- 從系統(tǒng)變量中刪除所有路徑
- 重新啟動(dòng)窗口
- 從其網(wǎng)站安裝了新的 Python
- 使用 pip install pyinstaller 安裝 Pyinstaller
- 在 cmd 中測(cè)試了我的 .py 代碼.它向我展示了所有丟失的包裹.
- 使用 pip install name-of-package 安裝了所有必需的包
- 通過(guò) pyinstaller -F -w --clean file.py 運(yùn)行最終命令
- (可選)根據(jù)需要安裝 Anaconda(不要將 Anaconda Python 添加為默認(rèn) Python.也不要將其路徑添加到系統(tǒng)變量中).
注意:您可以在其中構(gòu)建 virtualenv 并執(zhí)行 pyinstaller.
Note: You can build virtualenv and do pyinstaller in them.
我之前使用 anaconda 的嘗試導(dǎo)致文件大小為 212 MB.這個(gè)過(guò)程生成了一個(gè)大小為 27 MB 的 .exe 文件(僅導(dǎo)入 pandas 模塊).
My previous tries which used anaconda resulted in file of 212 MB in size. This process generated a .exe file of size 27 MB (Importing only pandas module).
這篇關(guān)于如何使pyinstaller不使用anaconda并構(gòu)建一個(gè)小型exe文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!