需要帮忙!!! OSError:[E050] 找不到模型“en_core_web_trf”。它似乎不是 Python 包或数据目录的有效路径
Posted
技术标签:
【中文标题】需要帮忙!!! OSError:[E050] 找不到模型“en_core_web_trf”。它似乎不是 Python 包或数据目录的有效路径【英文标题】:OSError: [E050] Can't find model 'en_core_web_trf'. It doesn't seem to be a Python package or a valid path to a data directory 【发布时间】:2021-08-07 07:42:07 【问题描述】:我正在尝试在 heroku 中部署一个应用程序,它成功完成,但是当我点击查看该应用程序时,它在红色框中显示此错误!!
OSError:[E050] 找不到模型“en_core_web_trf”。好像没有 是 Python 包或数据目录的有效路径。
这是我的代码
import spacy_streamlit
import streamlit as st
import pandas as pd
from spacy_transformers import Transformer
from spacy_transformers.pipeline_component import DEFAULT_CONFIG
DEFAULT_TEXT = """Google was founded in September 1998 by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University in California. Together they own about 14 percent of its shares and control 56 percent of the stockholder voting power through supervoting stock. They incorporated Google as a California privately held company on September 4, 1998, in California. Google was then reincorporated in Delaware on October 22, 2002."""
spacy_model = "en_core_web_trf"
st.title("Identifyer")
text = st.text_area("Text to analyze", DEFAULT_TEXT, height=200)
doc = spacy_streamlit.process_text(spacy_model, text)
spacy_streamlit.visualize_ner(
doc,
labels=["CARDINAL", "DATE", "EVENT", "FAC", "GPE", "LANGUAGE", "LAW", "LOC", "MONEY", "NORP", "ORDINAL", "ORG", "PERCENT", "PERSON", "PRODUCT", "QUANTITY", "TIME", "WORK_OF_ART"],
show_table=False,
title="filter",
)
df = pd.DataFrame(pd.DataFrame(
'type': ["ORG", "DATE", "EVENT", "FAC", "GPE", "LOC", "MONEY", "NORP", "PERCENT", "PERSON", "PRODUCT", "QUANTITY", "TIME", "WORK_OF_ART", "LANGUAGE", "LAW", "ORDINAL", "CARDINAL"],
'meaning': ["Companies, agencies, institutions, etc.", "Absolute or relative dates or periods", "Named hurricanes, battles, wars, sports events, etc.", "Buildings, airports, highways, bridges, etc.", "Countries, cities, states", "Non-GPE locations, mountain ranges, bodies of water", "Monetary values, including unit", "Nationalities or religious or political groups", "Percentage (including “%”)", "People, including fictional", "Vehicles, weapons, foods, etc. (Not services)", "Measurements, as of weight or distance", "Times smaller than a day", "Titles of books, songs, etc.", "Any named language", "Named documents made into laws", "first”, “second”, ...", "Numerals that do not fall under another type"],
))
df.index = [""] * len(df)
st.table(df)
【问题讨论】:
您是否验证了模型文件(或目录)可用于您的 heroku 实例? 感谢您的回复!但我怎么看? Spacy 网站上有说明如何安装模型。 spacy.io/models/en 我已经安装了模型!我什么都试过了! 您能否粘贴python -m spacy validate
的输出,在应用运行的完全相同的环境中运行?
【参考方案1】:
我创建了几个虚拟环境,我注意到,在最后两个中,模型“en_core_web_trf”没有用这个命令正确安装:python3 -m spacy download en_core_web_trf
,所以我得到了同样的错误。我不知道为什么,但是当我尝试 python 而不是 python3 时,它起作用了:python -m spacy download en_core_web_trf
。
如果没问题,你会看到这样的文字:
✔ Download and installation successful
You can now load the package via spacy.load('en_core_web_trf')
另一个有趣的点是,当我的应用程序在另一个虚拟环境中运行时,我无法在一个虚拟环境中安装模型。
如果有人能向我解释为什么会发生这种情况,以及为什么 python 正确安装了 spacy 模型,但 python3 没有,我将非常感激。 (我用的是 Kubuntu linux)
更新:
看起来您没有模型,或者安装不正确。如果您使用的是虚拟环境,请尝试使用pip show en_core_web_trf
检查您的模型版本,或者重新安装 spacy 和模型。
【讨论】:
感谢您的建议,但是没有用...有必要做spacy.load('en_core_web_trf')
吗?我的代码没有那部分
在许多类似 Debian 的系统(我猜可能包括 Kubuntu)上,python
是 python2 并且与 python3
完全不同。您可以通过python --version
查看。
@polm23 我检查了,我系统上的python和python3等于python版本3.8.5以上是关于需要帮忙!!! OSError:[E050] 找不到模型“en_core_web_trf”。它似乎不是 Python 包或数据目录的有效路径的主要内容,如果未能解决你的问题,请参考以下文章
python spacy [E050] Can't find model 'en_core_web_sm'
OSError: [WinError 126] 在 Python 中找不到指定的模块
我include自己的头文件,编译器却提示找不到,大家帮忙看看怎么回事好么?
OSError: [WinError 740] 请求的操作需要提升