pythonjam安装库_关于libtorrent库的安装

前言:

前段时间由于工作需要,在Python的web开发框架Django中使用到了libtorrent这个C++扩展库来解析链接或种子数据.特了解和尝试了libtorrent库的安装.一般情况下,为了方便Python解释器版本和依赖库的管理,python项目都是工作在虚拟环境之下.在此情况下,便出现了一个挺严重的问题:C++编写的libtorrent库如何引入到虚拟环境之中.

综述:

首先,项目中需要使用到libtorrent库;其次,如何把该库引入到Python的虚拟环境之中;最后,libtorrent的依赖环境是什么?

实现:

1.安装Boost:该函数库是libtorrent的依赖,同时也是C++的准标准库.###首先,在Linux终端安装boost的依赖:

sudo apt-get install mpi-default-dev

sudo apt-get install libicu-dev

sudo apt-get install Python-dev

sudo apt-get install libbz2-dev

###其次,官网下载boost安装包,最好选择压缩版,速度极慢---这是一个耗时操作!!!

下载完成,解压出来,切换到目录下:

方式一:

执行sudo ./bootstrap.sh ,生成b2;

若有需要,需要使用b2编译boost之前可能需要在boost的路径下修改project-config.jam文件,

把using python : 2.7 : /usr ;修改为python3.5;

最后执行sudo ./b2 install,大概编译半小时,boost安装完成.

whereis boost查看boost路径:

其中/usr/local/include存放boost头文件,/usr/local/lib存放boost函数库,该路径在libtorrent中可能会使用到.

--------------------------------------------------

方式二(不推荐):

sudo apt-get install libboost-dev(使用该种方式安装版本太低,和libtorrent最新版本不匹配)

2.安装libtorrent:sudo apt-get install libssl-dev

编译libtorrent,分别执行:

sudo ./configure --enable-python-binding --with-boost-python

sudo make

sudo make install

大概耗时30分钟左右,耐心等吧.

--------------------------------------------------

libtorrent安装成功后,修改profile文件,如下:

sudo vim /etc/profile

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

终端:

source /etc/profile

sudo reboot

3.将Ubuntu环境挂载到Python虚拟环境:创建Python虚拟环境时使用下述语句:

mkvirtualenv -p python3.5 apiserver --system-site-packages

4.追记:#### 很重要!!! ####

4.1.若需要Python3,在编译之前请把虚拟机默认的Python2改为Python3.which可查看存在路径.重命名就好了.等编译完成后再更改回去.

4.2.此外,请注意版本问题:libtorrent版本1.1.8,boost版本1.65.

4.3 安装完成后,若import libtorrent时抛出libtorrent-rasterbar.so.9: cannot open shared object file: No such file or directory的异常,请执行:

# cat /etc/ld.so.conf

include ld.so.conf.d/*.conf

# echo "/usr/local/lib" >> /etc/ld.so.conf

# ldconfig

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值