📜  OSError:[E941] 找不到模型“en”.看起来您正在尝试从快捷方式加载模型,该快捷方式自 spaCy v3.0 起已弃用.要加载模型,请改用其全名:- TypeScript (1)

📅  最后修改于: 2023-12-03 15:03:25.806000             🧑  作者: Mango

ImportError: cannot import name 'en'

The problem

When running a script using spaCy library, you may encounter the following error message:

OSError: [E941] Can't find model 'en'. It looks like you're trying to load a shortcut, which is deprecated as of spaCy v3.0, and will be removed in v4.0. To load the model, use its full name instead:
The solution

This error message is thrown because the spaCy shortcut models feature was removed in spaCy version 3.0. This means that any code calling a shortened model name, like "en", will trigger this error. To fix this error, you simply need to replace "en" with the full model name "en_core_web_sm". You can replace "sm" with "md" or "lg" to load the medium or large models, or use "en_core_web_trf" for the transformer-based model.

So, update your code from:

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

to:

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

This should fix the issue and allow you to continue using spaCy as intended.

Conclusion

The error message thrown when using the spaCy shortcut models feature is a result of a change made in spaCy 3.0. To avoid the error, replace the shortened model name with the full name of the model.