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已经安装。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值