使用spaCy加载英语模块时出错

问题描述

我正在用spaCy编写代码,并且在加载“ en”英语时,收到错误消息。

import spacy
nlp = spacy.load('en')

这是我导入的。我已经使用pip安装了nlp,spaCy和en_core_web_sm。 我为此使用PyCharm IDE。 这是我得到的错误

C:\Users\aayus\AppData\Local\Programs\Python\python36\python.exe "C:/Users/aayus/Desktop/MYP 5/ICT/ict_project/main.py"
Traceback (most recent call last):
  File "C:/Users/aayus/Desktop/MYP 5/ICT/ict_project/main.py",line 9,in <module>
    import sumarization
  File "C:\Users\aayus\Desktop\MYP 5\ICT\ict_project\sumarization.py",line 3,in <module>
    nlp = spacy.load('en')
  File "C:\Users\aayus\AppData\Local\Programs\Python\python36\lib\site-packages\spacy\__init__.py",line 30,in load
    return util.load_model(name,**overrides)
  File "C:\Users\aayus\AppData\Local\Programs\Python\python36\lib\site-packages\spacy\util.py",line 175,in load_model
    raise IOError(Errors.E050.format(name=name))
OSError: [E050] Can't find model 'en'. It doesn't seem to be a shortcut link,a Python package or a valid path to a data directory.

Process finished with exit code 1

有人可以帮我吗?预先感谢!

解决方法

使用全名加载小型英语模型:

import spacy
nlp = spacy.load('en_core_web_sm')

如果未下载模型,请在PyCharm终端中运行:

python -m spacy download en_core_web_sm