如何使pyinstaller不使用anaconda并构建一个小型exe文件 [英] How to make pyinstaller not use anaconda and build a small-size exe file

查看:23
本文介绍了如何使pyinstaller不使用anaconda并构建一个小型exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在 Windows 10 中使用 pyinstaller 构建 .exe 文件.它有效,但 exe 文件的大小约为 212 MB,即使使用 venv 也是如此(如 这里).我想这可能是因为我正在使用 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!

然后我安装了一个单独的 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 Filesanaconda3python.exe"中的 Python(此错误:C:Program Filesanaconda3python.exe"中没有 Python).但是我已经删除了所有到 anaconda 的路径.可能它一直试图到达 anaconda,这就是为什么我没有成功构建一个小尺寸的 .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?

推荐答案

终于,经过大量研究,可以解决我的问题:

Finally, after a lot of researching, could solve my problem:

  • 从我的电脑上卸载了所有的 python 和 anaconda
  • 从系统变量中删除所有路径
  • 重新启动窗口
  • 从其网站安装了新的 Python
  • 使用 pip install pyinstaller 安装 Pyinstaller
  • 在 cmd 中测试了我的 .py 代码.它向我展示了所有丢失的包裹.
  • 使用 pip install name-of-package
  • 安装了所有必需的包
  • 通过 pyinstaller -F -w --clean file.py 运行最终命令
  • (可选)根据需要安装 Anaconda(不要将 Anaconda Python 添加为默认 Python.也不要将其路径添加到系统变量中).

注意:您可以在其中构建 virtualenv 并执行 pyinstaller.

Note: You can build virtualenv and do pyinstaller in them.

我之前使用 anaconda 的尝试导致文件大小为 212 MB.这个过程生成了一个大小为 27 MB 的 .exe 文件(仅导入 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).

这篇关于如何使pyinstaller不使用anaconda并构建一个小型exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆