SpaCy OSError:找不到型号'en'

Mon*_*lal 21 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'
Run Code Online (Sandbox Code Playgroud)

我该怎么解决这个问题?

如果我不使用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')
Run Code Online (Sandbox Code Playgroud)

Joh*_*rum 32

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

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

  • 当我不使用sudo下载时,我会获得“下载成功但链接失败”的功能,但是为“ en”创建快捷方式链接不起作用(也许您没有管理员权限?),但是您仍然可以通过其完整包名称加载模型: nlp = spacy.load('en_core_web_sm')` (4认同)
  • 运行“python -m spacy download en”后,当我尝试加载“en”模型时,出现错误“OSError:[E049]找不到spaCy数据目录:'无'”。检查您的安装和权限,或者在必要时使用 spacy.util.set_data_path 自定义位置。`,有人如何解决它吗? (2认同)
  • @Cecilia:解决方法可能是``spacy.load('en_core_web_sm')``。关于“en_core_web_sm”管道的[文档](https://spacy.io/models/en#en_core_web_sm),这可能有助于确定它是否适用于您的情况。 (2认同)

Vet*_* PS 14

最终清除错误!

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

    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

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

    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

    • 更新为最新链接:

      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 --no-deps

感谢Github链接:-)

  • 可惜他们没有在模型导入失败的错误中抛出这些下载命令 (2认同)

Rag*_*ghu 8

1) 安装 Spacy

$ python -m spacy download en
Run Code Online (Sandbox Code Playgroud)

2)安装模型en_core_web_sm

$ python -m spacy download en_core_web_sm
>>> import spacy
>>> nlp = spacy.load("en_core_web_sm")
Run Code Online (Sandbox Code Playgroud)


Mon*_*lal 5

那好吧。事实证明,即使我的哪个Python正在显示anaconda python,当我使用python下载时,它仍将其链接到计算机上的python2.7 local。我使用以下命令修复了它:

$ sudo /scratch/sjn/anaconda/bin/python -m spacy download en
Run Code Online (Sandbox Code Playgroud)