我有一个程序,目前依赖于numpy
,我一直在努力转换py2exe
。我的问题是,即使脚本如减少py2exe分布大小,同时包括一些numpy功能
from numpy import array
print array(1)
,只有使用功能numpy.array
,我找不到任何方式排除,如在分配numpy.linalg
由创建numpy
包看似不必要的部分py2exe
。这导致分配大小超过80MB(压缩后为30MB)。在名为numpy.linalg._umath_linalg.pyd
的文件夹中有一个文件,它是34MB,另一个文件是numpy.linalg.lapack_lite.pyd
,它是18MB - 这些文件真的需要在那里吗?! .exe
仅在被删除时才会运行。
我的问题是,我该如何减少由此产生的分布大小?我知道有py2exe
替代方案,如果我可以删除依赖numpy
我不会有这个问题,但我想坚持这两个。
以下安装脚本是我正在使用的,导致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
相关:http://forums.xkcd.com/viewtopic.php?f=11&t=57929 – Siwel
呵呵奇怪。我系统上的这两个'.pyd'文件只有68和26 KB。你是如何安装Numpy的? –
文件大小取决于文件是否包含英特尔MKL/OpenBLAS/Atlas静态链接英寸等内容。如果您不需要快速线性代数,可以通过编译Numpy而不使用MKL/OpenBLAS/Atlas来缩小文件大小。 –