减少 pyinstaller exe 的大小 [英] Reducing size of pyinstaller exe

查看:27
本文介绍了减少 pyinstaller exe 的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 Pandas pyinstaller exe,它超过 40MB.

I have a simple pandas pyinstaller exe which is over 40MB.

我的exe示例:

import collections
import csv
import selenium
import pandas

print('hi')

40MB+ 似乎有点矫枉过正.

40MB+ for this seems a bit overkill.

我怎样才能尽可能减少这种情况?

How can I reduce this as much as possible?

一种方法:

pyinstaller --onefile --exclude matplotlib --exclude scipy --exclude pandas --exclude numpy.py

然而,考虑到排除列表有多大,这并不实用.

This however is not practical considering how big the exclusion list would be.

如何为 pyinstaller 选择一个文件夹以从中获取模块并排除其他所有内容,以便我可以拥有一个小应用程序?

How do I select a folder for pyinstaller to get modules from and exclude everything else so I may have a small application?

规范文件:

a = Analysis(['123.py'],
             pathex=['C:\Users\AA\ZZ'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='123',
          debug=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=True )

这也值得一提.默认情况下,Pyinstaller 不检测熊猫.

It's also worth mentioning. By default, Pyinstaller does not detect pandas.

添加:

hiddenimports = ['pandas._libs.tslibs.timedeltas']

To: C:Users<NAME>AppDataLocalProgramsPythonPython36Libsite-packagesPyInstallerhooks

使用多个可执行文件时可能的解决方案,可能是将每个可执行文件链接到一个单独的文件夹或具有所有导入的可执行文件.

A possible solution when using multiple executables, could be to link each executable to a separate folder or executable with all imports.

推荐答案

尝试使用 virtualenv 设置您的环境,并仅安装所需的库

try setting up your environment with a virtualenv, and install in there only the required libraries

关于使用虚拟环境的一些细节在这里:https://virtualenv.pypa.io/en/稳定/

some details on working with virtual env are here: https://virtualenv.pypa.io/en/stable/

这篇关于减少 pyinstaller exe 的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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