在Spacy中加载英语模块时出错

2022-05-15 00:00:00 python spacy

问题描述

我正在开发Ubuntu 16.04,Jupyter笔记本电脑。 我刚刚使用以下工具安装了最新版本的Spacy,因为我的英语模块没有下载

 conda install -c conda-forge spacy=2.0.11
但是,在使用上述命令安装Spacy时,它说: 以下程序包将被删除: 水蟒:5.2.0-PY36_3

通过以下方式加载英语模块:

import spacy
nlp = spacy.load('en')

我得到以下信息:

    KeyError                                  Traceback (most recent call last)
<ipython-input-15-76abff010c5f> in <module>()
----> 1 nlp = spacy.load('en')

~/anaconda3/lib/python3.6/site-packages/spacy/__init__.py in load(name, vocab, tokenizer, parser, tagger, entity, matcher, serializer, vectors, via)
     13     if depr_path not in (True, False, None):
     14         deprecation_warning(Warnings.W001.format(path=depr_path))
---> 15     return util.load_model(name, **overrides)
     16 
     17 

~/anaconda3/lib/python3.6/site-packages/spacy/util.py in get_package_by_name(name, via)
     42     """Import and load a Language class.
     43 
---> 44     lang (unicode): Two-letter language code, e.g. 'en'.
     45     RETURNS (Language): Language class.
     46     """

~/anaconda3/lib/python3.6/site-packages/sputnik/__init__.py in package(app_name, app_version, package_string, data_path)
    157         data_path = default_data_path(app_name)
    158 
--> 159     pool = Pool(app_name, app_version, expand_path(data_path))
    160     return pool.get(package_string)
    161 

~/anaconda3/lib/python3.6/site-packages/sputnik/pool.py in __init__(self, app_name, app_version, path, **kwargs)
     17 
     18     def __init__(self, app_name, app_version, path, **kwargs):
---> 19         super(Pool, self).__init__(app_name, app_version, path, **kwargs)
     20         self.logger = logging.getLogger(__name__)
     21         self.cleanup()

~/anaconda3/lib/python3.6/site-packages/sputnik/package_list.py in __init__(self, app_name, app_version, path, **kwargs)
     31             raise InvalidDataPathException(self.data_path)
     32 
---> 33         self.load()
     34 
     35     def packages(self):

~/anaconda3/lib/python3.6/site-packages/sputnik/package_list.py in load(self)
     49     def load(self):
     50         self._packages = {}
---> 51         for package in self.packages():
     52             self._packages[package.ident] = package
     53 

~/anaconda3/lib/python3.6/site-packages/sputnik/package_list.py in packages(self)
     45                 continue
     46 
---> 47             yield self.__class__.package_class(path=os.path.join(self.path, path))
     48 
     49     def load(self):

~/anaconda3/lib/python3.6/site-packages/sputnik/package.py in __init__(self, path)
     13     def __init__(self, path):
     14         meta = util.json_load(os.path.join(path, default.META_FILENAME))
---> 15         super(Package, self).__init__(defaults=meta['package'])
     16 
     17         self.logger = logging.getLogger(__name__)

KeyError: 'package'

请帮帮忙!


解决方案

您尝试过python -m spacy download en吗?您需要下载您想要解析的语言的Spacy模型。

相关文章