更新:推荐使用docker 这样每个用户在docker下都有root权限
安装allennlp 只需要 pip install allennlp # 不需要复杂的操作
************************************************************************
整体流程:anaconda+源码安装allenNLP
从清华镜像下载anaconda:
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
安装anaconda
bash Anaconda3-5.3.1-Linux-x86_64.sh
创建python3.6虚拟环境
conda create -n allennlp python=3.6.5
source activate allennlp
修改pip源 换为清华源
参考Pypi | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
下载allenNLP 源码
GitHub - allenai/allennlp: An open-source NLP research library, built on PyTorch.
之所以不安官方推荐的 使用 pip install allennlp 是因为 安装过程会出现 有些python 包不满足requirements.txt 中要求的版本, 比如spacy, 并且spacy的 en_core_web_sm 无法直接下载安装,需要下载源码 安装
修改 scripts/install_requirements.sh 和 requirements.txt
#!/bin/bash
pip install -r requirements.txt
#spacy download en_core_web_sm
注释掉最后一行, 手动源码安装 en_core_web_sm
allennlp/install_requirements.sh at master · allenai/allennlp · GitHub
接下来修改 requirements.txt
allennlp/requirements.txt at master · allenai/allennlp · GitHub
注释掉 spacy (我的版本的代码对应的是第23行)随后手动 安装spacy并指定版本,主要是requirements.txt 中的 spacy版本太高, 会导致 pip install allennlp失败
pytorch-pretrained-bert==0.1.2 找不到
改为 pytorch-pretrained-bert==0.2.0 这是我找到的最新版本, 换成最新版本即可。
接下来
INSTALL_TEST_REQUIREMENTS=true scripts/install_requirements.sh
接下来安装spacy并安装en_core_web_sm
pip install spacy==2.0.1 # 安装较低的版本能满足相关库的要求,不然会找不到
下载 es_core_news_sm-2.0.0
Releases · explosion/spacy-models · GitHub
# 安装en_core_web_sm包 这里需要注意 和spacy的版本兼容
pip install en_core_web_sm-2.0.0.tar.gz
下一步
pip install --editable . # .不能省
成功!
allennlp # 测试一下
输出如下:表示安装成功
![](https://img.haomeiwen.com/i15037811/174850307ab92f94.png)
也可以按下面的两个命令做测试:
bin/allennlp test-install
./scripts/verify.py
网友评论