在没有英特尔 MKL/BLAS/ATLAS/LAPACK 的情况下编译 numpy [英] Compile numpy WITHOUT Intel MKL/BLAS/ATLAS/LAPACK
问题描述
我正在使用 py2exe
来转换一个使用 numpy
的脚本,并且得到了一个非常大的结果文件夹,而且似乎很多大文件来自我没有使用的 numpy
包,例如 numpy.linalg
.
I am using py2exe
to convert a script which uses numpy
and am getting a very large resulting folder, and it seems a lot of the large files are from parts of the numpy
package that I'm not using, such as numpy.linalg
.
为了减少创建的文件夹的大小,我相信我应该在没有英特尔 MKL/BLAS/ATLAS/LAPACK 的情况下编译 numpy
.
To reduce the size of folder that is created, I have been led to believe I should have numpy
compiled without Intel MKL/BLAS/ATLAS/LAPACK.
我将如何进行此更改?
编辑
在 C:\Python27\Lib\site-packages\numpy\linalg
我找到了以下文件:_umath_linalg.pyd
(34MB) 和 lapack_lite.pyd
(18MB) 在使用 py2exe
时被复制到分发文件夹中.如果可能的话,我想消除对这些的依赖,同时仍然能够使用 numpy
数组.包含的另一个大文件位于 C:\Python27\Lib\site-packages\numpy\core
中,名为 _dotblas.pyd
(12MB).这个也能去掉吗?
EDIT
In C:\Python27\Lib\site-packages\numpy\linalg
I found the following files: _umath_linalg.pyd
(34MB) and lapack_lite.pyd
(18MB) which are being copied into the distribution folder when using py2exe
. If possible I would like to remove dependence on these while still being able to use numpy
arrays. The other large file being included is in C:\Python27\Lib\site-packages\numpy\core
and is called _dotblas.pyd
(12MB). Is it possible to remove this too?
推荐答案
根据 官方文档:
在 Numpy 中使用 ATLAS 和其他加速库可以通过以下方式禁用:
Disabling ATLAS and other accelerated libraries
Usage of ATLAS and other accelerated libraries in Numpy can be disabled via:
BLAS=None LAPACK=None ATLAS=None python setup.py build
然而,这个信息似乎已经过时了,因为我发现即使有这些选项 numpy v1.9.2 仍然会自动找到 libopenblas.so
:
However, this information seems to be out of date, since I found that even with these options numpy v1.9.2 was still automatically finding libopenblas.so
:
numpy_source_dir/$ BLAS=None LAPACK=None ATLAS=None python setup.py config
...
openblas_info:
FOUND:
libraries = ['openblas', 'openblas']
library_dirs = ['/opt/OpenBLAS/lib']
language = f77
FOUND:
libraries = ['openblas', 'openblas']
library_dirs = ['/opt/OpenBLAS/lib']
language = f77
...
一种解决方法是将 site.cfg.example
复制到 site.cfg
,然后编辑它以使相关 BLAS/LAPACK 库的路径无效:>
One workaround is to copy site.cfg.example
to site.cfg
, then edit it to make the paths to the relevant BLAS/LAPACK libraries invalid:
[openblas]
libraries =
library_dirs =
include_dirs =
当您随后调用 BLAS=None LAPACK=None ATLAS=None python setup.py config
时,您应该得到一个包含以下内容的输出:
When you subsequently call BLAS=None LAPACK=None ATLAS=None python setup.py config
you should get an output containing this:
...
openblas_info:
/home/alistair/src/python/numpy/numpy/distutils/system_info.py:594: UserWarning: Specified path is invalid.
warnings.warn('Specified path %s is invalid.' % d)
libraries not found in []
NOT AVAILABLE
...
我希望同样的方法适用于 ATLAS 和 MKL,尽管我没有安装这些库来进行适当的测试.
I expect that the same approach will work for ATLAS and MKL, although I don't have these libraries installed in order to do a proper test.
当然,您应该注意,如果没有加速的 BLAS/LAPACK 库,将对线性代数运算的性能产生大不利影响.
You should, of course, be aware that not having accelerated BLAS/LAPACK libraries will have a big detrimental effect on performance for linear algebra ops.
正如在下面的评论中提到的,您实际上并没有编译"当前版本的 numpy,而是从二进制分发版安装它.我上面给出的方法需要你从源代码构建 numpy,这在 Windows 中不是一件容易的事情(尽管有官方说明 此处).
As mentioned in the comments below, you didn't actually "compile" your current version of numpy, but rather installed it from a binary distribution. The approach I gave above would require you to build numpy from source, which is not an easy thing to do in Windows (although there are official instructions here).
更简单的选择是安装 Christoph Gohlke 网站上提供的 未优化
numpy 二进制文件之一这里.
A much easier option would be to install one of the unoptimized
numpy binaries available from Christoph Gohlke's website here.
这篇关于在没有英特尔 MKL/BLAS/ATLAS/LAPACK 的情况下编译 numpy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!