python - OSerror 导入语言模型 spacy
问题描述
我正在尝试使用 spacy 。我需要下载英语、意大利语和西班牙语的语言模型。我不能手动安装模型(因为我希望构建一段可移植的代码)所以我写了一个小函数,基本上是
import os
import spacy
lang='en'
try:
mod = lang+'_core_web_sm'
nlp = spacy.load(mod)
except:
print('model not present.. downloading and loading')
cmd = 'python -m spacy download '+ mod
os.system(cmd)
nlp = spacy.load(mod)
我在一个带有pip
python3、windows 10 的 virtualenv 中。
模型下载很好。这是 os.system(cmd) 的输出
从https://github.com/explosion/spacy-models/releases/download/it_core_news_sm-2.2.5/it_core_news_sm-2.2.5.tar.gz#egg=it_core_news_sm==2.2.5收集 it_core_news_sm==2.2.5 下载 https://github.com/explosion/spacy-models/releases/download/it_core_news_sm-2.2.5/it_core_news_sm-2.2.5.tar.gz fumagalli\classifybusiness\lib\site-packages (from spacy>=2.2.2->it_core_news_sm==2.2.5) (1.16.4) 要求已经满足:importlib-metadata>=0.20; c:\users\marco.fumagalli\classifybusiness\lib\site-packages 中的 python_version < "3.8" (来自目录<1.1.0,>=0.0.7->spacy>=2.2.2->it_core_news_sm==2.2。 5) (1.5.0) 要求已经满足:c:\users\marco.fumagalli\classifybusiness\lib\site-packages 中的 urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (从 requests<3.0.0,>=2.13.0->spacy>=2.2.2->it_core_news_sm==2.2.5) (1.23) 要求已经满足:chardet<4,>=3.0.2 in c:\users \marco.fumagalli\classifybusiness\lib\site-packages (来自 requests<3.0.0,>=2.13.0->spacy>=2.2.2->it_core_news_sm==2.2.5) (3.0.4) 要求已经满足: 证书>
但是何时spacy.load(mod)
执行:
OSError:[E050] 找不到模型“en_core_web_sm”。它似乎不是快捷链接、Python 包或数据目录的有效路径。
很奇怪,因为如果我这样做
import en_core_web_sm
en_core_web_sm.load()
有用。
我该如何解决?
谢谢
解决方案
尝试通过以下方式安装 en_core_web_sm:
pip3 install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.5/en_core_web_sm-2.2.5.tar.gz
推荐阅读
- variables - 为什么我必须插入一个变量才能像 SASS 中的 nth-child 伪类的参数一样使用它?
- mongodb - Spring中的Mongo更改流-打开连接问题
- c++ - 谁应该是选项卡控件子对话框的父级?
- javascript - 从服务器响应到特定房间(Python后端)后,React socket.io-client 不会重新渲染组件
- python - 为什么 NumPy 中的轴参数会改变?
- r - 在R中的字符串中替换“$”
- html - 清除画布画板jquery
- mysql - 优化内连接查询
- html - 带有过滤器和模态的 PDO 行查询
- kivy - Kivy Window 配置错误 - AttributeError: 'NoneType' 对象没有属性 'top'