简体   繁体   English

减少py2exe分布大小,同时包括一些numpy函数

[英]Reducing py2exe distribution size, while including some numpy functions

I have a program which is currently dependent on numpy which I have been working on converting with py2exe . 我有一个程序,目前依赖于numpy ,我一直在使用py2exe进行转换。 My issue is that even with a script such as 我的问题是,即使有一个脚本,如

from numpy import array
print array(1)

that only uses the function numpy.array , I can't find any way to exclude seemingly unnecessary parts of the numpy package such as numpy.linalg in the distribution that is created by py2exe . 只使用函数numpy.array ,我找不到任何方法来排除numpy包中看似不必要的部分,例如py2exe创建的分发中的numpy.linalg This results in the distribution being over 80MB in size, (30MB after being zipped). 这导致分发大小超过80MB(拉链后为30MB)。 There is a file in the folder called numpy.linalg._umath_linalg.pyd which is 34MB and another called numpy.linalg.lapack_lite.pyd which is 18MB - do these really need to be there?! 文件夹中有一个名为numpy.linalg._umath_linalg.pyd的文件,它是34MB,另一个名为numpy.linalg.lapack_lite.pyd ,它是18MB - 这些真的需要在那里吗?! The .exe does not run if they are simply deleted. 如果简单删除它们,则不会运行.exe

My question is, how can I reduce the resulting distribution size? 我的问题是, 如何减少分配大小? I am aware there are alternatives to py2exe and that if I could remove dependency on numpy I wouldn't have this problem, but I would like to stick with both of these. 我知道有py2exe替代品,如果我可以删除对numpy依赖我不会有这个问题,但我想坚持这两个。

The following setup script is what I am using, resulting in an 87MB distribution. 以下设置脚本是我正在使用的,导致87MB分发。

from distutils.core import setup
import py2exe, sys
import shutil

sys.argv.append('py2exe') # No need to type in command line.

py2exe_options = {
        # 'excludes': ['numpy.linalg'], # Stopped the resulting exe from running
        'compressed': True, # Saves 5MB, is this at the cost of some speed?
        'optimize': 1 # I don't really understand what this does.
        }

setup(
    windows=[{'script': 'main.pyw'}],
    options={'py2exe': py2exe_options},
    )

shutil.rmtree('build', ignore_errors=True) # Remove the build folder

If anyone has any further suggestions I'd like to here them! 如果有人有任何进一步的建议我想在这里! But here is what I've done so far. 但到目前为止我已经完成了这件事。

I have managed to reduce the size of the distribution from 87MB to 34MB by reinstalling numpy using an 'unoptimized' binary downloaded from here . 通过使用从此处下载的“未优化”二进制文件重新安装numpy我已设法将分发的大小从87MB减少到34MB。 I believe this is likely to run much slower when doing linear algebra operations, however it works fine for me working with arrays. 我相信在进行线性代数运算时这可能会运行得慢得多,但是对于我使用数组它可以正常工作。

UPDATE UPDATE
I have now got my distribution down to 28MB by altering the py2exe options in my setup.py script. 我现在通过更改setup.py脚本中的py2exe选项将我的发行版降低到28MB。

import distutils.core import setup

py2exe_options = {
        'compressed': True,
        'optimize': 1, # 2 does not work.
        'excludes': ['pydoc', 'doctest', 'pdb', 'inspect', 'pyreadline',
            'locale', 'optparse', 'pickle', 'calendar']
        }

setup(windows=['main.py'], options={'py2exe':py2exe_options})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM