在终端中正常工作时,如何在jupyter中使用spacy模型?

时间:2019-12-25 04:25:36

标签: spacy

我已经通过以下方式安装了spacy和模型

pip install -U spacy
python3 -m spacy download en_core_web_sm

并在我的终端中尝试如下,效果很好:

In [4]: import spacy
In [5]: spacy.load('en_core_web_sm')                                                             
Out[5]: <spacy.lang.en.English at 0x11a3b3a58>

然后我尝试在jupyter笔记本中访问它:

import spacy
spacy.load('en_core_web_sm') 
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-14-02379486adfb> in <module>
      1 import spacy
----> 2 spacy.load('en_core_web_sm')

~/.pyenv/versions/3.6.8/lib/python3.6/site-packages/spacy/__init__.py in load(name, **overrides)
     28     if depr_path not in (True, False, None):
     29         deprecation_warning(Warnings.W001.format(path=depr_path))
---> 30     return util.load_model(name, **overrides)
     31 
     32 

~/.pyenv/versions/3.6.8/lib/python3.6/site-packages/spacy/util.py in load_model(name, **overrides)
    167     elif hasattr(name, "exists"):  # Path or Path-like to model data
    168         return load_model_from_path(name, **overrides)
--> 169     raise IOError(Errors.E050.format(name=name))
    170 
    171 

OSError: [E050] Can't find model 'en_core_web_sm'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.

然后我在终端中检查了我的python版本的核心,在jupyter中也是如此:

In [3]: sys.executable                                                                           
Out[3]: '/Users/xxx/.pyenv/versions/3.6.8/bin/python3.6'

如何使en_core_web_sm在jupyter中工作?

0 个答案:

没有答案