OSError:[E050]找不到模型“en_core_web_trf”。它似乎不是 Python 包或数据目录的有效路径

Bru*_*uno 5 python heroku python-3.x spacy streamlit

我正在尝试在 heroku 中部署一个应用程序,并且它成功完成,但是当我单击查看该应用程序时,它在红色框中显示此错误!

\n
\n

OSError:[E050]找不到模型“en_core_web_trf”。它似乎不是 Python 包或数据目录的有效路径。

\n
\n

这是我的代码:

\n
import spacy_streamlit\nimport streamlit as st\nimport pandas as pd\nfrom spacy_transformers import Transformer\nfrom spacy_transformers.pipeline_component import DEFAULT_CONFIG\n\nDEFAULT_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."""\n\nspacy_model = "en_core_web_trf"\n\nst.title("Identifyer")\ntext = st.text_area("Text to analyze", DEFAULT_TEXT, height=200)\ndoc = spacy_streamlit.process_text(spacy_model, text)\n\nspacy_streamlit.visualize_ner(\n    doc,\n    labels=["CARDINAL", "DATE", "EVENT", "FAC", "GPE", "LANGUAGE", "LAW", "LOC", "MONEY", "NORP", "ORDINAL", "ORG", "PERCENT", "PERSON", "PRODUCT", "QUANTITY", "TIME", "WORK_OF_ART"],\n    show_table=False,\n    title="filter",\n)\n\ndf = pd.DataFrame(pd.DataFrame({\n'type': ["ORG", "DATE", "EVENT", "FAC", "GPE", "LOC", "MONEY", "NORP", "PERCENT", "PERSON", "PRODUCT", "QUANTITY", "TIME", "WORK_OF_ART", "LANGUAGE", "LAW", "ORDINAL", "CARDINAL"],\n'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 \xe2\x80\x9c%\xe2\x80\x9d)", "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\xe2\x80\x9d, \xe2\x80\x9csecond\xe2\x80\x9d, ...", "Numerals that do not fall under another type"],\n}))\n\ndf.index = [""] * len(df)\nst.table(df)\n
Run Code Online (Sandbox Code Playgroud)\n

Pal*_*ine 6

从 IDE 运行此命令:

!python -m spacy download en_core_web_trf
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

然后从菜单栏重新启动运行时(如果可用):

在此输入图像描述

现在,它将成功执行:

在此输入图像描述


fer*_*rum 0

我创建了几个虚拟环境,我注意到,在最后两个虚拟环境中,模型“en_core_web_trf”没有使用此命令正确安装:python3 -m spacy download en_core_web_trf,所以我得到了同样的错误。我不知道为什么,但是当我尝试使用python而不是python3时,它起作用了:python -m spacy download en_core_web_trf。\n如果没问题,您将看到以下文本:

\n

\xe2\x9c\x94 Download and installation successful\nYou can now load the package via spacy.load('en_core_web_trf')

\n

另一个有趣的点是,当我的应用程序在另一个虚拟环境中运行时,我无法在一个虚拟环境中安装模型。

\n

如果有人能向我解释为什么会发生这种情况,以及为什么 python 正确安装 spacy 模型,但 python3 却不能,我将非常感激。(我使用的是Kubuntu Linux)

\n

更新
\n看起来您没有型号,或者安装不正确。pip show en_core_web_trf如果您使用的是虚拟环境,请尝试检查您的模型版本,或者重新安装 spacy 和模型。

\n