centos6.6源碼安裝fasttext過程及error:‘nullptr’ 異常解決

centos6.6安裝fasttext包

官方教程
fasttext的安裝方式參考facebook在github上面的案例:
https://github.com/facebookresearch/fastText
官網提供了多種的安裝方式可以自己選擇。
fastext安裝所需的包:
gcc系統自帶
其他包可以直接通過pip的方式安裝
在這裏插入圖片描述
第一種方式:
可以到這個地址手動下載安裝包:
https://github.com/facebookresearch/fastText/releases
或者按照教程所示的方式,如下圖截圖,本人是下載.zip的包
在這裏插入圖片描述

# 下載安裝包
wget https://github.com/facebookresearch/fastText/archive/v0.9.1.zip
# 解壓包
unzip v0.9.1.zip
# 進入目錄
cd fastText-0.9.1
# 編譯
make

第二種方式:
pip的方式安裝

# 克隆github的fasttext包
git clone https://github.com/facebookresearch/fastText.git
cd fastText
# 注意有makefile文件的路徑 .
pip install .

如果沒有wget 或者unzip請執行:`

# wget 安裝
yum install wget
# unzip安裝
yum install unzip

建議使用第二種方式安裝,但是不管哪種方式安裝都要保證c++的版本滿足要求,否則安裝過程中不能正常的編譯。

注意:手動編譯的方式可能會出現錯誤:make編譯的過程出現錯誤error: ‘nullptr’ was not declared in this scope,這是由於4.4.7版本的gcc是不識別c++11語法的問題造成的,解決方案是升級gcc,重新編譯即可。
異常代碼:

c++ -pthread -std=c++0x -march=native -O3 -funroll-loops -DNDEBUG -c src/dictionary.cc
In file included from src/dictionary.cc:9:
src/dictionary.h:89: error: ‘nullptr’ was not declared in this scope
src/dictionary.cc: In member function ‘const std::vector<int, std::allocator<int> > fasttext::Dictionary::getSubwords(const std::string&) const’:
src/dictionary.cc:99: error: the default argument for parameter 2 of ‘void fasttext::Dictionary::computeSubwords(const std::string&, std::vector<int, std::allocator<int> >&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*) const’ has not yet been parsed
src/dictionary.cc: In member function ‘void fasttext::Dictionary::initNgrams():
src/dictionary.cc:203: error: the default argument for parameter 2 of ‘void fasttext::Dictionary::computeSubwords(const std::string&, std::vector<int, std::allocator<int> >&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*) const’ has not yet been parsed
src/dictionary.cc: In member function ‘void fasttext::Dictionary::threshold(int64_t, int64_t):
src/dictionary.cc:262: error: expected primary-expression before ‘[’ token
src/dictionary.cc:262: error: expected primary-expression before ‘]’ token
src/dictionary.cc:262: error: expected primary-expression before ‘const’
src/dictionary.cc:262: error: expected primary-expression before ‘const’
src/dictionary.cc:272: error: expected primary-expression before ‘[’ token
src/dictionary.cc:272: error: expected primary-expression before ‘]’ token
src/dictionary.cc:272: error: expected primary-expression before ‘const’
src/dictionary.cc:277: error:class std::vector<fasttext::entry, std::allocator<fasttext::entry> >’ has no member named ‘shrink_to_fit’
src/dictionary.cc: In member function ‘std::vector<long int, std::allocator<long int> > fasttext::Dictionary::getCounts(fasttext::entry_type) const’:
src/dictionary.cc:304: error: expected initializer before ‘:’ token
src/dictionary.cc:540: error: expected primary-expression at end of input
src/dictionary.cc:540: error: expected ‘;’ at end of input
src/dictionary.cc:540: error: expected primary-expression at end of input
src/dictionary.cc:540: error: expected ‘)’ at end of input
src/dictionary.cc:540: error: expected statement at end of input
src/dictionary.cc:540: error: expected ‘}’ at end of input
src/dictionary.cc: At global scope:
src/dictionary.cc:540: error: expected ‘}’ at end of input
make: *** [dictionary.o] Error 1

解決方案:升級gcc/g++到更高的版本重新編譯就可以安裝成功
CentOS6.6通過yum升級gcc/g++至版本4.8.2的方式參考博文:
https://blog.csdn.net/dijkstar/article/details/82218170

安裝完成後可在Python交互式環境導入模塊進行測試,模塊導入成功則證明fasttext已經安裝。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章