SpaCy OSError:找不到型号'en'

时间:2018-04-22 08:33:02

标签: nlp spacy

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

[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')

18 个答案:

答案 0 :(得分:25)

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

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

答案 1 :(得分:5)

哦,好吧。事实证明,即使我的哪个python显示anaconda python,当我使用python下载时,它将它连接到我的机器上的python2.7本地。我使用以下命令修复它:

192.168.0.123

答案 2 :(得分:5)

对于Windows用户,只需以管理员模式运行CMD并运行

python -m spacy download en

这将正确链接您的en模块。然后您可以使用

nlp = spacy.load('en')

答案 3 :(得分:4)

如果您使用的是Windows,请尝试以管理员身份打开cmd提示符/ Powershell。仅当您以管理员身份运行命令提示符时,才会发生模型的空链接(下载后)

答案 4 :(得分:2)

  

最终清除了错误!!!

  • 尝试了多个选项,包括:

    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

  • 自从使用我的公司网络以来,没有任何工作。最终,此命令像吊饰一样工作:-)

    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

感谢Github链接:-)

答案 5 :(得分:2)

在使用Anaconda时,以管理员身份打开Anaconda Prompt并执行以下命令

python -m spacy download en

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

spacy.load('en')

答案 6 :(得分:2)

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

  

sudo python3.6 -m spacy下载zh

与我一起,我的版本3.6 我希望它可以解决您的问题!

答案 7 :(得分:1)

我正在使用anaconda jupyter笔记本,并且遇到相同的错误。在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\wheels\48\5c\1c\15f9d02afc8221a668d2172446dd8467b20cdb9aef80a172a4
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笔记本中加载它,如下所示:

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

答案 8 :(得分:1)

  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')

答案 9 :(得分:1)

我在这里没有找到我的错误(对于所有使用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()

为我工作的表现很好:))

答案 10 :(得分:1)

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")

答案 11 :(得分:1)

在Windows上的Jupyter笔记本电脑上已出现此问题,并已修复:

使用管理员权限打开Anaconda提示

执行> python -m spacy下载zh

答案 12 :(得分:0)

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

下载要在SpaCy中加载的模型

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

在那里打开cmd。键入以下命令,然后按Enter键:

pip install en_core_web_md-1.2.0.tar.gz

以上命令可能会根据下载文件的版本而有所不同。

Voila!错误消失了:)

答案 13 :(得分:0)

试试这个-

导入en

nlp = en.load()

如果这有效,则表明该问题与spaCy检测已安装软件包的方式有关。如果它不起作用,并给您一个ImportError,则意味着模型安装所在的Python环境与Jupyter环境不同。

还可以再次检查模型是否正确安装?通过在子进程中运行pip将模型安装为Python软件包。而且pip错误有时可能会有些微妙,在输出中不会立即显而易见。

答案 14 :(得分:0)

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

python3 -m spacy下载zh

不仅是python -m .....

答案 15 :(得分:0)

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

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

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

    例如,对于python -m spacy链接/ Users / you / model en

这将创建一个指向您的语言模型的符号链接。现在,您可以在笔记本或脚本中使用spacy.load(“ en”)加载模型

答案 16 :(得分:0)

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

答案 17 :(得分:-1)

通过在Windows 10计算机上以管理员身份运行命令提示符来下载spacy解决了链接问题

C:\Users\mrawat>python -m spacy download en
Requirement already satisfied: en_core_web_sm==2.1.0 from https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.1.0/en_core_web_sm-2.1.0.tar.gz#egg=en_core_web_sm==2.1.0 in c:\users\mrawat\appdata\local\programs\python\python37\lib\site-packages (2.1.0)
You are using pip version 19.0.3, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
✔ Download and installation successful
You can now load the model via spacy.load('en_core_web_sm')
symbolic link created for C:\Users\mrawat\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\data\en <<===>> C:\Users\mrawat\AppData\Local\Programs\Python\Python37\lib\site-packages\en_core_web_sm
✔ Linking successful
C:\Users\mrawat\AppData\Local\Programs\Python\Python37\lib\site-packages\en_core_web_sm
-->
C:\Users\mrawat\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\data\en
You can now load the model via spacy.load('en')