ubuntu16.04环境下安装Python SPAMS包

来源:互联网 发布:树莓派安装unity3d 编辑:程序博客网 时间:2024/06/05 02:04

ubuntu16.04环境下安装Python SPAMS包

最近想用SPAMS做一些稀疏学习的东西,按照网上的步骤装了两天都没成功,最后在老潘的协助下半小时搞定。
在安装SPAMS之前需要安装的有:

  • BLAS
  • ATLAS
  • LAPACK

BLAS

下载文件后,对压缩包进行解压,进入目录,执行命令为:
gfortran -c -O3 *.f # 编译所有的 .f 文件,生成 .o文件
ar rv libblas.a *.o # 链接所有的 .o文件,生成 .a 文件
su cp libblas.a /usr/local/lib # 将库文件复制到系统库目录
(参考)

ATLAS

为了省事直接使用命令sudo apt-get install libatlas-dev来进行安装。SPAMS安装说明里说ATLAS要好于BLAS。反正两个都装了。
(参考)

LAPACK

下了几个版本按照网上的步骤自己编译,都还ok不过在下一步安装SPAMS时就报错了,build setup.py 时出现:

g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/spams_wrap.o -lstdc++ -lblas -llapack -o build/lib.linux-x86_64-2.7/_spams_wrap.so -fopenmp -s/usr/bin/ld: //usr/local/lib/liblapack.a(sgesvd.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC//usr/local/lib/liblapack.a: error adding symbols: Bad valuecollect2: error: ld returned 1 exit statuserror: command 'g++' failed with exit status 1

重试几次,无果·······
后来解决方案是···

sudo apt-get install liblapack-dev

所以 apt-get install 是个好东西

SPAMS

最后安装SPAMS。我下载的是2.6.0的Python版本,按照README说明安装就ok:

tar zxf spams-python-v2.6-2017-04-18.tar.gzcd spams-pythonpython setup.py buildinst=<your-python-install-dir>python setup.py install --prefix=$inst

最后试一下:

sp@ubuntu:~/Desktop/spams-python$ ipythonPython 2.7.12 (default, Nov 19 2016, 06:48:10) Type "copyright", "credits" or "license" for more information.IPython 2.4.1 -- An enhanced Interactive Python.?         -> Introduction and overview of IPython's features.%quickref -> Quick reference.help      -> Python's own help system.object?   -> Details about 'object', use 'object??' for extra details.In [1]: import spamsIn [2]: 

all done
good luck

原创粉丝点击