Python SciPy 需要 BLAS 吗? [英] Does Python SciPy need BLAS?

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

问题描述

numpy.distutils.system_info.BlasNotFoundError: 
    Blas (http://www.netlib.org/blas/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [blas]) or by setting
    the BLAS environment variable.

我需要从该站点下载哪个 tar?

Which tar do I need to download off this site?

我已经尝试过 fortrans,但是我一直收到这个错误(显然是在设置了环境变量之后).

I've tried the fortrans, but I keep getting this error (after setting the environment variable obviously).

推荐答案

用于提供构建和安装的 SciPy 网页指令,但那里的指令现在依赖于操作系统二进制分发.要在没有所需库的预编译包的操作系统上构建 SciPy(和 NumPy),您必须构建并静态链接到 Fortran 库 BLASLAPACK:

The SciPy webpage used to provide build and installation instructions, but the instructions there now rely on OS binary distributions. To build SciPy (and NumPy) on operating systems without precompiled packages of the required libraries, you must build and then statically link to the Fortran libraries BLAS and LAPACK:

mkdir -p ~/src/
cd ~/src/
wget http://www.netlib.org/blas/blas.tgz
tar xzf blas.tgz
cd BLAS-*

## NOTE: The selected Fortran compiler must be consistent for BLAS, LAPACK, NumPy, and SciPy.
## For GNU compiler on 32-bit systems:
#g77 -O2 -fno-second-underscore -c *.f                     # with g77
#gfortran -O2 -std=legacy -fno-second-underscore -c *.f    # with gfortran
## OR for GNU compiler on 64-bit systems:
#g77 -O3 -m64 -fno-second-underscore -fPIC -c *.f                     # with g77
gfortran -O3 -std=legacy -m64 -fno-second-underscore -fPIC -c *.f    # with gfortran
## OR for Intel compiler:
#ifort -FI -w90 -w95 -cm -O3 -unroll -c *.f

# Continue below irrespective of compiler:
ar r libfblas.a *.o
ranlib libfblas.a
rm -rf *.o
export BLAS=~/src/BLAS-*/libfblas.a

仅执行五个 g77/gfortran/ifort 命令之一.我已经注释掉了所有内容,但是我使用的 gfortran.后续的 LAPACK 安装需要 Fortran 90 编译器,并且由于两个安装应该使用相同的 Fortran 编译器,g77 不应该用于 BLAS.

Execute only one of the five g77/gfortran/ifort commands. I have commented out all, but the gfortran which I use. The subsequent LAPACK installation requires a Fortran 90 compiler, and since both installs should use the same Fortran compiler, g77 should not be used for BLAS.

接下来,您需要安装 LAPACK 的东西.SciPy 网页的说明在这里也对我有所帮助,但我不得不修改它们以适应我的环境:

Next, you'll need to install the LAPACK stuff. The SciPy webpage's instructions helped me here as well, but I had to modify them to suit my environment:

mkdir -p ~/src
cd ~/src/
wget http://www.netlib.org/lapack/lapack.tgz
tar xzf lapack.tgz
cd lapack-*/
cp INSTALL/make.inc.gfortran make.inc          # On Linux with lapack-3.2.1 or newer
make lapacklib
make clean
export LAPACK=~/src/lapack-*/liblapack.a

2015 年 9 月 3 日更新:今天验证了一些评论(感谢大家):在运行 make lapacklib 之前编辑 make.inc 文件并将 -fPIC 选项添加到 OPTSNOOPT 设置.如果您使用的是 64 位架构或想要编译为 64 位架构,还需要添加 -m64.BLAS 和 LAPACK 编译时这些选项设置为相同的值很重要.如果你忘记了 -fPIC SciPy 实际上会给你一个关于缺少符号的错误,并会推荐这个开关.make.inc 的特定部分在我的设置中如下所示:

Update on 3-Sep-2015: Verified some comments today (thanks to all): Before running make lapacklib edit the make.inc file and add -fPIC option to OPTS and NOOPT settings. If you are on a 64bit architecture or want to compile for one, also add -m64. It is important that BLAS and LAPACK are compiled with these options set to the same values. If you forget the -fPIC SciPy will actually give you an error about missing symbols and will recommend this switch. The specific section of make.inc looks like this in my setup:

FORTRAN  = gfortran 
OPTS     = -O2 -frecursive -fPIC -m64
DRVOPTS  = $(OPTS)
NOOPT    = -O0 -frecursive -fPIC -m64
LOADER   = gfortran

在旧机器上(例如 RedHat 5),gfortran 可能安装在旧版本(例如 4.1.2)中并且不理解选项 -frecursive.在这种情况下,只需将其从 make.inc 文件中删除即可.

On old machines (e.g. RedHat 5), gfortran might be installed in an older version (e.g. 4.1.2) and does not understand option -frecursive. Simply remove it from the make.inc file in such cases.

Makefile 的 lapack 测试目标在我的设置中失败,因为它找不到 blas 库.如果你很彻底,你可以暂时将 blas 库移动到指定位置来测试 lapack.我是一个懒惰的人,所以我相信开发人员只在 SciPy 中让它工作和验证.

The lapack test target of the Makefile fails in my setup because it cannot find the blas libraries. If you are thorough you can temporarily move the blas library to the specified location to test the lapack. I'm a lazy person, so I trust the devs to have it working and verify only in SciPy.

这篇关于Python SciPy 需要 BLAS 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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