如何从 pyInstaller 中删除/排除模块和文件? [英] How to remove/exclude modules and files from pyInstaller?

查看:213
本文介绍了如何从 pyInstaller 中删除/排除模块和文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试缩小我的 python exe 文件的大小,我一直在环顾四周,但似乎找不到删除额外模块的好答案.目前,我发现它正在删除我需要的模块,而不是我告诉它的模块.文档相当无用,到目前为止我也没有找到示例.

I'm trying to shrink the size of my python exe file, I've been looking around but I can't seem to find a good answer for removing extra modules. At the moment, I'm discovering that it's deleting modules I need instead of the ones I'm telling it to. The documentation is rather unhelpful and neither are examples I've found so far.

我的规范文件:

a = Analysis(['D:\\<path>\\<scriptName>.py'],
         pathex=['c:\\bin\\pyinstaller-2.0'],
         hiddenimports=[],
         hookspath=None,
         )

pyz = PYZ(a.pure)
exe = EXE(pyz,
      a.zipfiles,
      a.scripts,
      a.binaries,
      a.datas + [('data/Sounds/Cycle.wav', 'D:\\<path>\\data\\Sounds\\Cycle.wav','DATA'),
       ('data/Sounds/Hold.wav', 'D:\\<path>\\data\\Sounds\\Hold.wav','DATA'),
       ('data/Sounds/Timer.wav', 'D:\\<path>\\data\\Sounds\\Timer.wav','DATA'),
       ('data/Sounds/Warn.wav', 'D:\\<path>\\data\\Sounds\\Warn.wav','DATA'),
       ],
      name=os.path.join('dist', 'timer.exe'),
      debug=False,
      strip=False,
      upx=False,
      icon=r"D:\<path>\Icon.ico",
      console=True )

现在,我想开始排除事物,但是对于如何排除事物似乎没有很好的解释.

Now, I want to start excluding things, but there doesn't seem to be a very explanation of how to exclude things.

这些是我在使用 py2exe 时排除的:

These are things I had excluded when using py2exe:

'win32', 'unittest', _ssl, 'python25.dll', 'w9xpopen.exe', 'wx'
'python25.dll', 'API*', 'KERNALBASE.dll', 'DEVOBJ.dll','CRMGR32.dll',
'POWERPROF.dll', 'msvcm90.dll', 'msvcp90.dll', 'msvcr90.dll'

虽然如果我将这些中的任何一个添加到 a.binaries

Though if I add any of these into the a.binaries as

a.binaries -[('wx')],

它会删除 PyQt4.dll 文件.其他人也是如此.我不遵循那个逻辑.我认为,至少,如果它一开始找不到它们,它就会跳过它们而不是删除其他东西.

it deletes the PyQt4.dll files instead. Same holds true for the others. I do not follow that logic. I would think, at the very least, if it couldn't find them in the first place it would just skip over them instead of deleting other things.

py2exe 使我成为 26mb 文件 + 三个文件(exe、library.zip 和 w9xpopen.exe)pyInstaller 为我制作了一个 11mb 的文件和一个文件.

py2exe makes me a 26mb files + three files (exe, library.zip, and w9xpopen.exe) pyInstaller makes me an 11mb file, and one file.

我觉得我可以把它变小,但这排除了让我困惑的事情.它直接忽略了 msv dll 文件并将它们放入.

I feel I can make it smaller, but this excludes thing is confusing me. It straight up ignores the msv dll files and puts them in anyway.

使用 Python 2.7,PyQt4 4.9.x

Using Python 2.7, PyQt4 4.9.x

推荐答案

对我有用的解决方案是:

The solution that worked for me was:

excluded_binaries = [
        'VCRUNTIME140.dll',
        'msvcp140.dll',
        'mfc140u.dll']
a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries])

这篇关于如何从 pyInstaller 中删除/排除模块和文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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