SpaCy OSError: Can't find model 'en'

SpaCy OSError: Can't find model 'en'

即使我下载了模型也无法加载它

[jalal@goku entity-sentiment-analysis]$ which python
/scratch/sjn/anaconda/bin/python
[jalal@goku entity-sentiment-analysis]$ sudo python -m spacy download en
[sudo] password for jalal: 
Collecting https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz
  Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz (37.4MB)
    100% |████████████████████████████████| 37.4MB 9.4MB/s 
Installing collected packages: en-core-web-sm
  Running setup.py install for en-core-web-sm ... done
Successfully installed en-core-web-sm-2.0.0

    Linking successful
    /usr/lib/python2.7/site-packages/en_core_web_sm -->
    /usr/lib64/python2.7/site-packages/spacy/data/en

    You can now load the model via spacy.load('en')

import spacy 

nlp = spacy.load('en')
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-0fcabaab8c3d> in <module>()
      1 import spacy
      2 
----> 3 nlp = spacy.load('en')

/scratch/sjn/anaconda/lib/python3.6/site-packages/spacy/__init__.py in load(name, **overrides)
     17             "to load. For example:\nnlp = spacy.load('{}')".format(depr_path),
     18             'error')
---> 19     return util.load_model(name, **overrides)
     20 
     21 

/scratch/sjn/anaconda/lib/python3.6/site-packages/spacy/util.py in load_model(name, **overrides)
    118     elif hasattr(name, 'exists'):  # Path or Path-like to model data
    119         return load_model_from_path(name, **overrides)
--> 120     raise IOError("Can't find model '%s'" % name)
    121 
    122 

OSError: Can't find model 'en'

我应该如何解决这个问题?

如果我不使用 sudo 下载 en 模型,我得到:

Collecting https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz
  Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz (37.4MB)
    100% |████████████████████████████████| 37.4MB 9.6MB/s ta 0:00:011   62% |████████████████████            | 23.3MB 8.6MB/s eta 0:00:02
Requirement already satisfied (use --upgrade to upgrade): en-core-web-sm==2.0.0 from https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz in /scratch/sjn/anaconda/lib/python3.6/site-packages
You are using pip version 10.0.0, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

    Error: Couldn't link model to 'en'
    Creating a symlink in spacy/data failed. Make sure you have the required
    permissions and try re-running the command as admin, or use a
    virtualenv. You can still import the model as a module and call its
    load() method, or create the symlink manually.

    /scratch/sjn/anaconda/lib/python3.6/site-packages/en_core_web_sm -->
    /scratch/sjn/anaconda/lib/python3.6/site-packages/spacy/data/en


    Download successful but linking failed
    Creating a shortcut link for 'en' didn't work (maybe you don't have
    admin permissions?), but you can still load the model via its full
    package name:

    nlp = spacy.load('en_core_web_sm')

通过使用 sudo python ...,您可以为与本地解释器不同的 python 解释器安装模型。事实上,它在您的日志中说 spaCy 模型安装到 /usr/lib64/python2.7/site-packages/ 而不是 /scratch/sjn/anaconda/lib/python3.6/site-packages/

尝试 运行 python -m spacy download en 它应该将模型安装到正确的目录。

哦,好吧。结果即使我的 which python 正在显示 anaconda python,当我使用 python 下载时它正在将它链接到我机器上的本地 python2.7。我使用以下命令修复了它:

$ sudo /scratch/sjn/anaconda/bin/python -m spacy download en

FINALLY CLEARED THE ERROR !!!

现在安装的最佳方式

pip install -U pip setuptools wheel

pip install -U spacy

python -m spacy download en_core_web_sm

Always Open Anaconda Prompt / Command Prompt with Admin Rights to avoid Linking errors!!!

  • 尝试了多种选择,包括:

    python -m spacy download en

    conda install -c conda-forge spacy

    python -m spacy download en_core_web_sm

    python -m spacy link en_core_web_sm en

  • None 自从我使用我的 公司网络 以来就一直在工作。最后,这个 命令就像一个魅力:-)

    pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz --no-deps

    • 更新为最新 Link :

    pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz --no-deps

感谢更新 Github Links :-)

1) 安装 Spacy

$ python -m spacy download en

2) 安装模型en_core_web_sm

$ python -m spacy download en_core_web_sm
>>> import spacy
>>> nlp = spacy.load("en_core_web_sm")

Bc 我在这里没有发现我的错误(对于使用 jupyter Notebook、Alteryx、Company Network 并遇到此错误的每个人):

我试图用 python 创建一个用于主题检测的宏,但得到的错误是没有名为 "en_core_web_sm" 的模块

在开头使用以下代码安装以下包:

从 ayx 导入包 Package.installPackages(['pandas','numpy','matplotlib', 'gensim', 'spacy', 'pyLDAvis', 'https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.1.0/en_core_web_sm-2.1.0.tar.gz'])

如果您引用模块使用:

进口en_core_web_sm

nlp = en_core_web_sm.load()

对我来说效果很好 :))

我正在使用 anaconda jupyter notebook,但遇到了同样的错误。 运行 在 anaconda 提示符下的命令(运行 作为管理员)它解决了我的问题:

(base) C:\WINDOWS\system32>conda install -c conda-forge spacy
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\yadav\Anaconda3

  added / updated specs:
    - spacy


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    cymem-2.0.3                |   py37h6538335_0          35 KB  conda-forge
    cython-blis-0.4.1          |   py37hfa6e2cd_0         4.3 MB  conda-forge
    murmurhash-1.0.0           |   py37h6538335_0          17 KB  conda-forge
    plac-0.9.6                 |             py_1          18 KB  conda-forge
    preshed-3.0.2              |   py37h6538335_1          89 KB  conda-forge
    spacy-2.2.1                |   py37he980bc4_0         7.4 MB  conda-forge
    srsly-0.2.0                |   py37h6538335_0         189 KB  conda-forge
    thinc-7.1.1                |   py37he980bc4_0         1.4 MB  conda-forge
    wasabi-0.4.0               |             py_0          19 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        13.4 MB

The following NEW packages will be INSTALLED:

  cymem              conda-forge/win-64::cymem-2.0.3-py37h6538335_0
  cython-blis        conda-forge/win-64::cython-blis-0.4.1-py37hfa6e2cd_0
  murmurhash         conda-forge/win-64::murmurhash-1.0.0-py37h6538335_0
  plac               conda-forge/noarch::plac-0.9.6-py_1
  preshed            conda-forge/win-64::preshed-3.0.2-py37h6538335_1
  spacy              conda-forge/win-64::spacy-2.2.1-py37he980bc4_0
  srsly              conda-forge/win-64::srsly-0.2.0-py37h6538335_0
  thinc              conda-forge/win-64::thinc-7.1.1-py37he980bc4_0
  wasabi             conda-forge/noarch::wasabi-0.4.0-py_0


Proceed ([y]/n)? Y


Downloading and Extracting Packages
cython-blis-0.4.1    | 4.3 MB    | ############################################################################ | 100%
cymem-2.0.3          | 35 KB     | ############################################################################ | 100%
srsly-0.2.0          | 189 KB    | ############################################################################ | 100%
thinc-7.1.1          | 1.4 MB    | ############################################################################ | 100%
plac-0.9.6           | 18 KB     | ############################################################################ | 100%
spacy-2.2.1          | 7.4 MB    | ############################################################################ | 100%
preshed-3.0.2        | 89 KB     | ############################################################################ | 100%
wasabi-0.4.0         | 19 KB     | ############################################################################ | 100%
murmurhash-1.0.0     | 17 KB     | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done


(base) C:\WINDOWS\system32>python -m spacy download en
Collecting en_core_web_sm==2.2.0
  Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz (12.0MB)
     |████████████████████████████████| 12.0MB 409kB/s
Requirement already satisfied: spacy>=2.2.0 in c:\users\yadav\anaconda3\lib\site-packages (from en_core_web_sm==2.2.0) (2.2.2)
Requirement already satisfied: numpy>=1.15.0 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (1.16.2)
Requirement already satisfied: thinc<7.4.0,>=7.3.0 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (7.3.1)
Requirement already satisfied: wasabi<1.1.0,>=0.3.0 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (0.4.0)
Requirement already satisfied: requests<3.0.0,>=2.13.0 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (2.21.0)
Requirement already satisfied: setuptools in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (40.8.0)
Requirement already satisfied: plac<1.2.0,>=0.9.6 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (1.1.3)
Requirement already satisfied: srsly<1.1.0,>=0.1.0 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (0.2.0)
Requirement already satisfied: cymem<2.1.0,>=2.0.2 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (2.0.3)
Requirement already satisfied: importlib-metadata>=0.20; python_version < "3.8" in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (0.23)
Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (1.0.2)
Requirement already satisfied: blis<0.5.0,>=0.4.0 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (0.4.1)
Requirement already satisfied: preshed<3.1.0,>=3.0.2 in c:\users\yadav\anaconda3\lib\site-packages (from spacy>=2.2.0->en_core_web_sm==2.2.0) (3.0.2)
Requirement already satisfied: tqdm<5.0.0,>=4.10.0 in c:\users\yadav\anaconda3\lib\site-packages (from thinc<7.4.0,>=7.3.0->spacy>=2.2.0->en_core_web_sm==2.2.0) (4.36.1)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\yadav\anaconda3\lib\site-packages (from requests<3.0.0,>=2.13.0->spacy>=2.2.0->en_core_web_sm==2.2.0) (2019.3.9)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in c:\users\yadav\anaconda3\lib\site-packages (from requests<3.0.0,>=2.13.0->spacy>=2.2.0->en_core_web_sm==2.2.0) (1.24.1)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\yadav\anaconda3\lib\site-packages (from requests<3.0.0,>=2.13.0->spacy>=2.2.0->en_core_web_sm==2.2.0) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\yadav\anaconda3\lib\site-packages (from requests<3.0.0,>=2.13.0->spacy>=2.2.0->en_core_web_sm==2.2.0) (3.0.4)
Requirement already satisfied: zipp>=0.5 in c:\users\yadav\anaconda3\lib\site-packages (from importlib-metadata>=0.20; python_version < "3.8"->spacy>=2.2.0->en_core_web_sm==2.2.0) (0.6.0)
Requirement already satisfied: more-itertools in c:\users\yadav\anaconda3\lib\site-packages (from zipp>=0.5->importlib-metadata>=0.20; python_version < "3.8"->spacy>=2.2.0->en_core_web_sm==2.2.0) (6.0.0)
Building wheels for collected packages: en-core-web-sm
  Building wheel for en-core-web-sm (setup.py) ... done
  Created wheel for en-core-web-sm: filename=en_core_web_sm-2.2.0-cp37-none-any.whl size=12019131 sha256=f716e80f029462a80e9fb79ef353c1ac8c0f81d3754778bb6fec520d640fcc87
  Stored in directory: C:\Users\yadav\AppData\Local\Temp\pip-ephem-wheel-cache-bvy0x0eg\wheelsccf9d02afc8221a668d2172446dd8467b20cdb9aef80a172a4
Successfully built en-core-web-sm
Installing collected packages: en-core-web-sm
  Found existing installation: en-core-web-sm 2.0.0
    Uninstalling en-core-web-sm-2.0.0:
      Successfully uninstalled en-core-web-sm-2.0.0
Successfully installed en-core-web-sm-2.2.0
✔ Download and installation successful
You can now load the model via spacy.load('en_core_web_sm')
symbolic link created for C:\Users\yadav\Anaconda3\lib\site-packages\spacy\data\en <<===>> C:\Users\yadav\Anaconda3\lib\site-packages\en_core_web_sm
✔ Linking successful
C:\Users\yadav\Anaconda3\lib\site-packages\en_core_web_sm -->
C:\Users\yadav\Anaconda3\lib\site-packages\spacy\data\en
You can now load the model via spacy.load('en')

(base) C:\WINDOWS\system32>

然后在 jupyter notebook 中加载如下:

nlp = spacy.load('en',parse=True,tag=True, entity=True)

如果你使用其他 python 版本,你可以 运行 :

sudo python3.6 -m spacy download en

有我,我的3.6版本 希望对您的问题有所帮助!

转到https://github.com/explosion/spacy-models

在SpaCy中下载你要加载的模型

将下载的文件粘贴到 Anaconda 文件夹中的 SpaCy 文件夹中

在那里打开cmd。输入以下命令并按回车键:

pip install en_core_web_md-1.2.0.tar.gz

以上命令可能因下载文件的版本而异。

瞧!错误消失了:)

由于您正在使用 Anaconda,请以管理员身份打开 Anaconda Prompt 并执行以下命令

python -m spacy download en

要在 Jupyter Notebook 中加载 Spacy 'en',请使用以下命令

spacy.load('en')

由于您使用的是 python 版本 3.6,请尝试使用 -

python3 -m spacy 下载 en

而不仅仅是 python -m .....

  pip install https://github.com/explosion/spacy- 
  models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz

  #fixes an permission error when attempting to create the symlinks on windows 10

  python -m spacy link en_core_web_sm en_core_web_smc

  from Jupyter notes
  import spacy

  nlp = spacy.load('en_core_web_sm')

如果您已经下载了 spacy 和语言模型(例如,en_core_web_sm 或 en_core_web_md),那么您可以按照以下步骤操作:

  1. 以管理员身份打开 Anaconda 提示符

  2. 然后输入:python -m spacy link [包名或路径] [快捷方式]

    例如,python -m spacy link /Users/you/model en

这将为您的语言模型创建一个符号link。现在您可以在笔记本或脚本中使用 spacy.load("en") 加载模型

  • 您需要下载en_core_web_sm
  • 如果您正在使用 anaconda ,则 运行 此命令
  • conda install -c conda-forge spacy-model-en_core_web_sm
  • 并将其加载为
  • nlp= spacy.load('en_core_web_sm')

快速修复:安装一个可用的模型(例如 en_core_web_sm),然后自己制作 symlink。复制两条路径 spacy 说它不能 link (可能是由于虚拟环境 运行 没有管理员提升)并使用例如mklink 在 Windows.

例如mklink /D C:\Users\USER\PROJECT\venv2\lib\site-packages\spacy\data\en C:\Users\USER\PROJECT\venv2\lib\site-packages\en_core_web_sm