Boost.python的源码编译安装(尝试解决Boost.Python.ArgumentError)
2018-03-02 15:44
1306 查看
问题描述
在本人尝试用pycaffe运行一个程序(snntoolbox)时,出现了Boost.Python.ArgumentError: Python argument types in Net.__init__(Net, unicode, int) did not match C++ signature:的报错,在翻过各大论坛的相关回答和官方网站的教程之后,主要意见有:1.传递参数类型与函数声明中不一致;2.Boost不应该由
sudo apt install安装,而应该直接由源码根据自身的python进行编译(build against python version)。
根据本人的情况分析(pycaffe+snntoolbox运行),更有可能是由于第二个原因引起,因此尝试解决这个问题的话,自然要学习如何通过源码编译安装。(结果学会了从源码安装boost,但是没能够解决报错,猜想可能是因为:a.卸载不干净,b.caffe的Makefile里面的设置问题)
本人对于boost是个门外汉,文章应该有蛮多纰漏的,欢迎指正。
boost简要介绍
boost: Boost库是为C++语言标准库提供扩展的一些C++程序库的总称。boost.python:它是boost库的一部分,随boost一起安装,用来实现C++和Python代码的交互。
libboost-dev的卸载
如果你之前已经用sudo apt install libboost-dev libboost-all-dev的方式安装了boost(比如你在Ubuntu16.04下按照CUDA官网推荐方式安装了caffe的话),建议先卸载。
卸载方式如下:
sudo apt remove libboost-dev libboost-all-dev
Boost.python的编译安装
说明:因为caffe需要boost的支持,在卸载以后所有boost文件都需要通过安装(对于非boost.python来说,安装就是将头文件拷贝到PREFIX路径[默认为/usr/local]),不只boost.python(boost.python不是headers-only文件,需要单独build)step1:源码文件的下载和解压
首先,按照boost官网下载指引描述,到所示网站下载boost源码的压缩文件,当前时间的文件是boost_1_66_0.tar.bz2,放在$HOME目录下。
~$ tar --bzip2 -xvf boost_1_66_0.tar.bz2 ~$ cd boost_1_66_0 ~/boost_1_66_0$ ./bootstrap.sh
#返回信息如下 Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2 Detecting Python version... 2.7 Detecting Python root... /usr Unicode/ICU support for Boost.Regex?... not found. Backing up existing Boost.Build configuration in project-config.jam.1 Generating Boost.Build configuration in project-config.jam... #配置文件名为project-config.jam Bootstrapping is done. To build, run: ./b2 #通常的下一步操作 To adjust configuration, edit 'project-config.jam'. Further information: - Command line help: ./b2 --help #如果需要更详细的说明,运行左边的命令后再根据需要修改自己的命令 - Getting started guide: http://www.boost.org/more/getting_started/unix-variants.html - Boost.Build documentation: http://www.boost.org/build/doc/html/index.html[/code]
我们应关注上述返回信息,包括配置文件名和一些使用提示。step2:重新编译boost
这一步是为了保险起见,将所有boost相关文件都重新编译,运行一下命令:~/boost_1_66_0$ ./b2 -a
关注shell返回信息中,建议将路径1加入#include path,将路径2加入#compiler path,以下根据指引设置环境变量。step3:设置环境变量
~$ sudo gedit ~/.profile #根据上一步shell中返回的信息,在打开的文件中加入如下两行信息 export BOOST_INCLUDE=$HOME/boost_1_66_0 export BOOST_LIB=$HOME/boost_1_66_0/stage/lib #保存后关闭文件 ~$source ~/.profile
step4:验证安装boost成功
对于我来说,因为caffe是需要boost支持的,验证方式是在caffe文件夹下重新编译Makefile.config,依次make all,make test,make runtest直至最后测试完全通过。
当然简单的方式,应该是调用库,运行一小段代码呗。~$ touch sample.cpp ~$ sudo gedit sample.cpp
向打开的文件中填入以下代码#include <string> #include <iostream> #include <boost/version.hpp> #include <boost/timer.hpp> using namespace std; int main() { boost::timer t; cout << "max timespan: " << t.elapsed_max() / 3600 << "h" << endl; cout << "min timespan: " << t.elapsed_min() << "s" << endl; cout << "now time elapsed: " << t.elapsed() << "s" << endl; cout << "boost version" << BOOST_VERSION <<endl; cout << "boost lib version" << BOOST_LIB_VERSION <<endl; return 0; }~$ g++ sample.cpp -o sample.out #编译生成sample.out文件 ~$ ./sample.out #查看输出
得到以下输出max timespan: 2.56205e+09h min timespan: 1e-06s now time elapsed: 0.000135s boost version105800#好吧,真的是没有卸载干净.... boost lib version1_58参考资料
boost官方指引
Ubuntu上完全编译安装boost
相关文章推荐
- 关于安装xgboost和lightGBM的python3封装的问题" Error: setup script specifies an absolute path"及其解决办法
- Greenplum源码编译安装ORCA握手失败解决 - Caused by SSLError(SSLError("bad handshake: ...)
- 解决Python扩展程序编译安装的error: command 'mt.exe' failed with exit status 31
- windows下安装python的C扩展编译环境(解决“error: command 'cl.exe' failed: No such file or directory”)
- 【解决】SPECCPU编译出错“f951: error: argument to '-O' should be a non-negative integer”
- apache源码编译安装时报错:configure: error: ...No recognized SSL/TLS toolkit detected
- mysql源码编译安装时error: No curses
- CentOS编译安装perl、python及问题解决
- Win7安装vs2008编译报LINK : Internal error during IncrBuildImage--解决方法
- CentOS-5.2上使用源码安装SystemTap-1.1遇到的问题(SEC_ERROR_PKCS11_GENERAL_ERROR)及解决办法
- 通过mk文件编译android4.0.3系统app源码后覆盖安装失败解决办法(android odex文件)
- 用Python(x,y)安装的MinGW32编译boost
- python32版本,出现问题“struct.error: argument for 's' must be a bytes object”的解决办法
- Ubuntu12.04编译Android4.0.1源码全过程-----附wubi安装ubuntu编译android源码硬盘空间不够的问题解决
- Mac OS X 10.8.3搭建Android工程源码的编译环境(解决找不到GCC、GIT、PYTHON的问题)
- 64位centos上nginx,php编译安装遇configure: error: Cannot find libmysqlclient under /usr 错误解决
- 编译源码时出现 Checking API: checkapi-last (unknown): error 17解决方法
- 编译安装PHP出现configure: error: mysql configure failed. Please check config.log的解决方法
- 已经安装rubygems源码配置并编译python with zlib
- 编译源码时出现 Checking API: checkapi-last (unknown): error 17解决方法