关于libtorrent库的安装
生活随笔
收集整理的這篇文章主要介紹了
关于libtorrent库的安装
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
- 前言:
前段時間由于工作需要,在Python的web開發框架Django中使用到了libtorrent這個C++擴展庫來解析鏈接或種子數據.特了解和嘗試了libtorrent庫的安裝.一般情況下,為了方便Python解釋器版本和依賴庫的管理,python項目都是工作在虛擬環境之下.在此情況下,便出現了一個挺嚴重的問題:C++編寫的libtorrent庫如何引入到虛擬環境之中. - 綜述:
首先,項目中需要使用到libtorrent庫;其次,如何把該庫引入到Python的虛擬環境之中;最后,libtorrent的依賴環境是什么? -
實現:
###首先,在Linux終端安裝boost的依賴:sudo apt-get install mpi-default-devsudo apt-get install libicu-devsudo apt-get install Python-devsudo 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最新版本不匹配)
1.安裝Boost:該函數庫是libtorrent的依賴,同時也是C++的準標準庫.2.安裝libtorrent:
sudo apt-get install libssl-dev編譯libtorrent,分別執行:sudo ./configure --enable-python-binding --with-boost-pythonsudo makesudo make install大概耗時30分鐘左右,耐心等吧. --------------------------------------------------libtorrent安裝成功后,修改profile文件,如下:sudo vim /etc/profileexport LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH終端:source /etc/profilesudo reboot3.將Ubuntu環境掛載到Python虛擬環境:
創建Python虛擬環境時使用下述語句:mkvirtualenv -p python3.5 apiserver --system-site-packages4.追記:
#### 很重要!!! ####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.confinclude ld.so.conf.d/*.conf# echo "/usr/local/lib" >> /etc/ld.so.conf# ldconfig
總結
以上是生活随笔為你收集整理的关于libtorrent库的安装的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习笔记2
- 下一篇: java基础加强_补充笔记