如何使pyinstaller不使用anaconda并生成小型exe文件 [英] How to make pyinstaller not use anaconda and build a small-size exe file
问题描述
我一直试图在Windows 10中使用pyinstaller来生成.exe文件.它可以工作,但是即使使用venv,exe文件的大小也约为212 MB(如
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!
然后,我安装了单独的Python版本,以免使用anaconda!但是它没有用(仍然是大文件).
Then I installed a separate version of Python so not to use anaconda! But it did not work (still large file).
然后我卸载了anaconda进行测试. Pyinstaller仍在尝试访问"C:\ Program Files \ anaconda3 \ python.exe"中的Python(此错误:在"C:\ Program Files \ anaconda3 \ python.exe"中没有Python).但是,我已经删除了前往蟒蛇的所有路径.也许它一直试图到达anaconda,这就是为什么我未能成功构建一个小的.exe文件的原因.
Then I uninstalled anaconda to test it. Pyinstaller is still trying to access Python in 'C:\Program Files\anaconda3\python.exe' (this error: No Python at 'C:\Program Files\anaconda3\python.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?
推荐答案
最后,经过大量研究,可以解决我的问题:
Finally, after a lot of researching, could solve my problem:
- 从我的PC上卸载所有python和anaconda
- 从系统变量中删除了所有路径
- 重新启动窗口
- 从其网站安装了新的Python
- 使用pip install pyinstaller安装了Pyinstaller
- 在cmd中测试了我的.py代码.它向我显示了所有丢失的软件包.
- 使用 pip install-of-package 安装所有必需的软件包
- 由pyinstaller -F -w --clean file.py发出的最后命令
- (可选)如果需要,请安装Anaconda(不要将Anaconda Python添加为默认python.也不要将其路径添加到系统变量中.)
- Uninstalled all pythons and anaconda from my PC
- Removed all Path from the system variables
- Restarted the windows
- Installed a fresh Python from its website
- Installed Pyinstaller using pip install pyinstaller
- Tested my .py code in cmd. It showed me all the packages that are missing.
- Installed all required packages by using pip install name-of-package
- Ran final command by pyinstaller -F -w --clean file.py
- (Optional) Install Anaconda if you need (don't add Anaconda Python as the default python. Also don't add its path to the system variables).
注意:您可以构建virtualenv并在其中进行pyinstaller.
Note: You can build virtualenv and do pyinstaller in them.
我以前使用anaconda进行的尝试导致文件大小为212 MB.此过程生成了一个大小为27 MB的.exe文件(仅导入熊猫模块).
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).
这篇关于如何使pyinstaller不使用anaconda并生成小型exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!