Ubuntu 15.04 安装 boost-python


1. 安装依赖库


sudo apt-get install python-dev
sudo apt-get install mpi-default-dev #安装mpi库
sudo apt-get install libicu-dev  #支持正则表达式的UNICODE字符集
sudo apt-get install libbze-dev  # 如果编译出现错误:bzlib.h : No such file or directory
sudo apt-get update

2. 手动安装Boost


2.1 下载 boost源代码,然后编译 boost (C++11 Python fPIC),或者访问 boost.org.

#解压
unzip boost_1_63_0.zip
cd boost_1_63_0
./bootstrap.sh --with-python=PYTHON
./bootstrap.sh --with-libraries=system,thread,python

会生成 b2和bjam文件。可查看使用方法

./bootstrap.sh -help

2.2 编译 boost

sudo ./b2 install 
./b2 cxxflags=-fPIC cflags=-fPIC --c++11

成功后会出现

The Boost C++ Libraries were successfully built!

2.3 建立一个 test.cpp文件测试

gedit test.cpp

添加如下内容

#include<iostream>
#include<boost/bind.hpp>
using namespace std;
using namespace boost;
int fun(int x, int y){return x+y;}
int main(){int m=1; int n=2;cout<<boost::bind(fun,_1,_2)(m,n)<<endl;return 0;}

编译

g++ test.cpp -o test

执行

./test

结果

3

3. 安装gflags


3.1 下载 gflags


安装命令,安装参数详细介绍见INSTALL.md


3.2 编辑CMakeList

gedit CMakeLists.txt

添加 -fPIC选项(在文件靠近开头的地方添加下面一行):

set (CMAKE_POSITION_INDEPENDENT_CODE True) 

生成Makefile

cmake .

检查是否在CMakeFiles/flags.cmake中成功生成-fPIC

grep -R fPIC ./build/CMakeFiles/  

出现如下结果

./build/CMakeFiles/gflags_nothreads_static.dir/flags.make:CXX_FLAGS = -03 -DNDEBUG -fPIC
./build/CMakeFiles/gflags_static.dir/flags.make:CXX_FLAGS = -03 -DNDEBUG -fPIC

3.3 编译 gflags (+ fPIC)

make 
make test   #(optional) 
sudo make install

4. 配置


4.1 在工程的根目录下创建boost-build.jam,添加下列行

cd boost_1_63_0
gedit bootstrap.jam

添加如下内容

boost-build /home/bids/boost_1_63_0/tools/build/src

其中后面的这个路径应该为你本机里包含bootstrap.jam的路径。


然后在包装c++函数给python的源码文件目录中添加Jamroot文件。


4.2 编辑 jamroot

gedit jamroot

添加如下示例如下(详见中文注释)

# Copyright David Abrahams 2006. Distributed under the Boost  
# Software License, Version 1.0. (See accompanying  
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)  import python ;  if ! [ python.configured ]  
{   ECHO "notice: no Python configured in user-config.jam" ;   ECHO "notice: will use default configuration" ;  using python ;  
}  # Specify the path to the Boost project.  If you move this project,  
# adjust this path to refer to the Boost root directory.  # 注:此目录应该指向工程自己的boost-build.jam所在目录  
use-project boost  : /home/bids/boost_1_63_0/tools/build/src ;  # Set up the project-wide requirements that everything uses the  
# boost_python library from the project whose global ID is  
# /boost/python.  
# 注:下面示例动态库so工程,文件路径应该指向你自己的这两个.a文件的安装路径  
project  : requirements <link>shared  <library-file>/usr/local/lib/libboost_python.a  <library-file>/usr/local/lib/libgflags.a  ;  # Declare the three extension modules.  You can specify multiple  
# source files after the colon separated by spaces.  
# 注:此处应包含所有生成so所需要编译的源代码文件  
python-extension word_net : wordnet_python_wrapper.cc wordnet_tool.cc word_tool.cc utils.cc ;  # Put the extension and Boost.Python DLL in the current directory, so  
# that running script by hand works.  
install convenient_copy   : word_net   : <install-dependencies>on <install-type>SHARED_LIB <install-type>PYTHON_EXTENSION   <location>.   ;  # A little "rule" (function) to clean up the syntax of declaring tests  
# of these extension modules.  
local rule run-test ( test-name : sources + )  
{  import testing ;  testing.make-test run-pyd : $(sources) : : $(test-name) ;  
}  # Declare test targets  
# 注:建议添加test脚本配置  
run-test wordnet : word_net wordnet_python_test.py ;  


参考文献


在Ubuntu上安装boost库

Ubuntu 14.04 安装boost-python并配置工程指南

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/246860.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python 常见问题汇总(待续)

1. No module named skimage pip install scikit-image --upgrade 2. No module named dicom sudo pip install pydicom 3. python name ‘os’ is not defined import os This will import the python’s module os, which apparently is used later in the code of your m…

如何将 ipynb 发布到 blog 中(html, markdown格式)

相关文章链接 如何向IPython Notebook中导入.py文件 如何将 ipynb 发布到 blog 中(html, markdown格式) Introducing IPython Notebook Beginner’s IPython Notebook Tutorial Example notebook showing how to do statistics in IPython Notebook next generation slide…

HP Z840 工作站配sSAS Raid 安装 Ubuntu 16.04 系统

惠普Z840工作站配SAS RAID安装win7系统加载驱动 安装ubuntu的最低版本版本要求是01.25&#xff0c;请更新到官方最新的02.31测试 1. BIOS系统更新 1. 准备好一个空的U盘&#xff0c;格式化成FAT32&#xff0c;在U盘上建立\Hewlett-Packard\BIOS\New 2. 下载链接http://ftp.hp…

Ubuntu SSH Algorithm negotiation failed

问题 解决方法 chmod 777 /etc/ssh/sshd_configgedit /etc/ssh/sshd_config添加如下 Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbcMACs hmac-md5,hmac-sha1,umac-64openssh.…

不同matlab版本所支持的gcc g+版本

问题 关于 GCC 和 G 版本问题 Matlab 2014a gcc/g 4.7.x, Matlab 2016a gcc/g 4.9.x Matlab 2017a gcc/g 4.9.x Ubuntu 15.04 gcc/g 4.9.x, Ubuntu 16.04 gcc/g 5.4.x 原则上Matlab需要和Ubuntu版本一致&#xff0c;由于CUDA 8只支持16.04,而且需要GCC 5.4.x 进行编译&#…

Linux系统中添加硬盘,并挂载到已有的目录,比如/home/user

备份用户下数据 cd home ls newuser tar cvf newuser.tar newuser  &#xff03;创建一个tar归档 rm -rf newuser mkdir newuser备注&#xff1a;newuser为home下的用户。 分区和挂载 #查看硬盘分区 fdisk -l#分区 fdisk /dev/sdbCommand (m for help):m#新建一个分区 Comman…

高性能Numpy/Scipy加速:使用Intel MKL和Intel Compilers或OpenBLAS(待续)

Numpy/Scipy加速:使用Intel MKL和Intel Compilers 1.获取Intel Parallel Studio XE Intel免费软件工具提供免费的软件包&#xff0c;其中包括完整的Intel编译器和计算库及其激活码&#xff0c;软件和激活码一一对应。注意需要使用教育邮箱注册&#xff0c;否则不予通过。 2.安装…

Linux 安装卸载软件及管理软件仓库

软件仓库 Linux的软件包都存放在一个地方&#xff0c;叫做软件仓库&#xff0c;repository。 因为Linux是在Windows之后诞生的&#xff08;1991年前后&#xff09;&#xff0c;所以为了避免Windows的这个“弊端”&#xff0c;Linux选择创建一个集中存放软件的地方。 当然了&a…

Linux 终端配置

一般Linux中的配置文件大多以点开头&#xff0c;而且多以rc结尾。比如vim的配置文件 .vimrc&#xff0c;bash shell的配置文件.bashrc&#xff0c;等等。 像这样的配置文件&#xff0c;如果用ls -l命令是列不出来的&#xff0c;需要用ls -a来列出。 “rc”&#xff0c;它是“…

Caffe2 Compilation Error gflags.cc' is being linked both statically and dynamically into this execut

问题描述 python -c from caffe2.python import core 2>/dev/null && echo "Success" || echo "Failure" 出现这个问题 ERROR: something wrong with flag flagfile in file /home/bids/softwares/gflags-2.2.0/src/gflags.cc. One possibil…

值得关注的医疗 AI 公司(待续)

医疗成像 Clearview Diagnostics 是一家开发辅助医生诊断疾病的工具的 AI 软件公司。该公司最初的重点是乳腺癌。 Butterfly Network 是一家医疗成像技术公司&#xff0c;该公司创建了一个集成了深度学习技术的便携式医疗成像设备&#xff0c;帮助缺乏医疗机构或医生不够专业的…

caffe2 介绍

Caffe2的特性 Caffe2框架可以通过一台机器上的多个GPU或具有一个及多个GPU的多台机器来进行分布式训练。 也可以在iOS系统、Android系统和树莓派&#xff08;Raspberry Pi&#xff09;上训练和部署模型。只需要运行几行代码即可调用Caffe2中预先训练好的Model Zoo模型。Caffe2…

如何向IPython Notebook中导入.py文件

相关文章链接 如何向IPython Notebook中导入.py文件 如何将 ipynb 发布到 blog 中(html, markdown格式) Introducing IPython Notebook Beginner’s IPython Notebook Tutorial Example notebook showing how to do statistics in IPython Notebook next generation sli…

Python 中的numpy 库

待总结 用scikit-learn和pandas学习线性回归 用scikit-learn和pandas学习Ridge回归 待整理的 Numpy & Pandas numpy——主要对其 N 维数组对象有用 http://www.numpy.org/ Pandas数据转为 numpy数据 df_numpyMatrix df.as_matrix() df_numpyMatrixdf.values a([3.23…

Python 中的Pandas库

待总结 用scikit-learn和pandas学习线性回归 用scikit-learn和pandas学习Ridge回归 基于python的数据分析库Pandas pandas——Python 数据分析库&#xff0c;包括数据框架&#xff08;dataframes&#xff09;等结构 http://pandas.pydata.org/ 10 Minutes to Pandas&#…

weka和matlab完成完整分类实验

本文 本文简单介绍数据集介绍、weka的使用、weka与LIBSVM、matlab与LIBSVM以及分类的若干细节问题。 1. 数据集介绍 打开网址UCI数据集&#xff0c;如下图。 从右下角可以看到Iris这个数据集&#xff0c;这是使用最多的数据集&#xff0c;目前下载量超过了82万。 打开之后跳…

Python 中的绘图matplotlib mayavi库

python matplotlib 图像可视化 python-data-visualization-course Interactive Web Plotting for Python Interactive Web Plotting for Python-github 待整理的 Matplotlib Introduction to Matplotlib and basic line matplotlib——一个 2D 绘图库&#xff0c;可产生…

python -pass的用法

空语句 熟悉C/C的经常会这样写判断语句&#xff1a; if&#xff08;ture&#xff09;expression; else;//do nothing 那在Python里面怎么去表达空语句呢&#xff0c;这时候就用到了pass。 number input(请输入一个数) if number 5:print(your numbers is 5) else:pass 实际…

python -lambda表达式的用法

匿名函数 lambda的意义&#xff1a; 利用lambda我们可以速写函数&#xff0c;不用去定义函数就可以直接使用 y lambda x,z:59*x8*z print(y(2,4)) 从例子中可以看到&#xff0c;lambda的语法结构是&#xff1a; lambda input : output expression lambda的用法比较简单&…

ubuntu 16.04 配置Python2.7 和 Python3.5 同时调用OpenCV

安装OpenCV OpenCV 官网&#xff0c;下载见 SourceForge and GitHub。 若使用官网版本安装不成功&#xff0c;则可试试Github版本。 或者 git clone https://github.com/Itseez/opencv.git 安装依赖库 sudo apt-get -y install libopencv-dev sudo apt-get -y install bui…