AttributeError:类型对象'spacy.syntax.nn_parser.array'没有属性'__reduce_cython__',(向虚拟环境添加路径)

时间:2019-04-10 10:42:00

标签: python anaconda virtualenv spacy lemmatization

总体问题

我正在从事一个nlp项目,并希望使用spacy。但是,当尝试为nlp对象加载语言时,我总是遇到错误:

AttributeError: type object 'spacy.syntax.nn_parser.array' has no attribute '__reduce_cython__'

代码:

    test = nlp('many people like laughing while they are running')
    for word in test:
        print(word.text,word.lemma)

我不确定,但是问题可能与我正在使用的虚拟环境有关。我发现一种解决方案建议“将spaCy路径添加到virtualenv中的PYTHONPATH”

所以我实际的2个问题是: 1)您认为我的问题在哪里? 2)如果您认为问题与虚拟环境有关,该如何在virtualenv中将spaCy路径添加到PYTHONPATH?

预先感谢您的帮助

背景信息:

我是一个初学者,所以我对堆栈溢出,venvs和了解我的问题所需的信息了解不多。这就是我能给你的:

我正在关注本教程: https://github.com/bhargavvader/personal/tree/master/notebooks/text_analysis_tutorial

我的环境:

Operating System: Linux Mint 19.1 Cinnamon
Python Version Used: Python 3.7.1
spaCy Version Used: 2.1.3

我正在通过蟒蛇使用python

我到目前为止所做的: 当然,我在互联网上搜索了错误 这是我的错误日志:

到目前为止我做了什么

1)我卸载并重新安装了辣味

2)我签出了spacy文件

我如何理解这是错误日志中发生错误的部分?:

----> 4从.pipes导入Tagger,DependencyParser,EntityRecognizer

因此,我查看了我的spacy文件夹以检出管道脚本。但是找不到函数Tagger,DependencyParser和EntityRecognizer调用' reduce_cython '

的地方

1)我已经在互联网上搜索了错误日志:

据我了解,所提出的类似问题并没有帮助我解决问题:

与我的问题类似的唯一问题是: https://github.com/explosion/spaCy/issues/2439

他们的解决方案是“在virtualenv中将spaCy路径添加到PYTHONPATH”

因此,我搜索了如何向cette python路径添加路径,并发现: How do I add a path to PYTHONPATH in virtualenv

但是我对答案还不太了解。而且我仍然不确定这是否是问题所在。因此,如果您知道我的问题的答案,或者可以给我一些有关如何继续解决此问题的指导。我会放心的。

其他信息:

如果这很重要,那么按照我之前提到的教程,我确实遇到了无法下载需求的问题。 这是我的任期给我的:

Could not open requirements file: [Errno 2] No such file or directory: 'REQUIREMENTS_1.txt'

我忽略了它,因为起初一切都很顺利。

错误日志

AttributeError跟踪(最近一次通话)  在 ----> 1 nlp = spacy.load('en')       2       3测试= nlp(“许多人在跑步时喜欢笑”)       测试中的单词4:       5打印(word.text,word.lemma)

加载中的

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / init .py(名称,**覆盖)      从.glossary导入13解释      14个来自.about导入版本 ---> 15从.errors导入错误,警告,deprecation_warning      来自的16。导入工具      17

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / util.py in load_model(name,** overrides)     110“”“     111如果isinstance(path,basestring_): -> 112 return Path(路径)     其他113条:     114返回路径

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / util.py在load_model_from_link(name,** overrides)中     127 if Path(name).exists():#模型数据目录的路径     128 return load_model_from_path(Path(name),**覆盖) -> 129 elif hasattr(name,“ exists”):#路径或类似路径的模型数据     130 return load_model_from_path(name,** overrides)     131提高IOError(Errors.E050.format(name = name))

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / data / en / init .py在加载中(**覆盖)      10      11 def负载(**覆盖): ---> 12返回load_model_from_init_py(文件,**覆盖)

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / util.py在load_model_from_init_py(init_file,** overrides)中     171 def load_model_from_init_py(init_file,**覆盖):     172“”“ Helper函数,用于模型包的load()方法中 -> 173 init .py。     174     175 init_file(unicode):模型的 init .py的路径,即__file__

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / util.py在load_model_from_path(model_path,meta,** overrides)中     141 return cls.load(** overrides)     142 -> 143     144 def load_model_from_package(name,** overrides):     145“”“从已安装的程序包中加载模型。”“”

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / util.py在get_lang_class(lang)中      48“”“      49种全球语言 ---> 50个返回语言的语言      51      52

import_module中的

〜/ anaconda3 / lib / python3.7 / importlib / init .py(名称,程序包)     125休息     126级+ = 1 -> 127 return _bootstrap._gcd_import(name [level:],包,级别)     128     129

〜/ anaconda3 / lib / python3.7 / importlib / _bootstrap.py在_gcd_import(名称,包,级别)中

〜/ anaconda3 / lib / python3.7 / importlib / _bootstrap.py在_find_and_load(name,import _)

〜/ anaconda3 / lib / python3.7 / importlib / _bootstrap.py in _find_and_load_unlocked(name,import _)

〜/ anaconda3 / lib / python3.7 / importlib / _bootstrap.py在_load_unlocked(spec)中

〜/ anaconda3 / lib / python3.7 / importlib / _bootstrap_external.py在exec_module(自身,模块)中

〜/ anaconda3 / lib / python3.7 / importlib / _bootstrap.py in _call_with_frames_removed(f,* args,** kwds)

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / lang / en / init .py in      从..tokenizer_exceptions 13导入BASE_EXCEPTIONS      14从..norm_exceptions导入BASE_NORMS ---> 15 from ...语言导入语言      16 ...来自... attrs import LANG,NORM      17 ...从... util import update_exc,add_lookups

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / language.py在      15从.vocab导入Vocab      从.lemmatizer导入16的Lemmatizer --->从17.pipeline导入DependencyParser,Tensorizer,Tagger,EntityRecognizer      从.pipeline导入18,SimilarityHook,TextCategorizer,Sentencizer      从.pipeline中导入19,merge_noun_chunks,merge_entities,merge_subtokens

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / pipeline / init .py in       2从未来导入unicode_literals       3 ----> 4从.pipes导入Tagger,DependencyParser,EntityRecognizer       5从.pipes导入TextCategorizer,Tensorizer,Pipe和Sentencizer       6从.entityruler导入EntityRuler

初始化spacy.pipeline.pipes()中的

pipes.pyx

〜/ anaconda3 / lib / python3.7 / site-packages / spacy / syntax / nn_parser.cpython-37m-x86_64-linux-gnu.so在初始spacy.syntax.nn_parser()

AttributeError:类型对象'spacy.syntax.nn_parser.array'没有属性' reduce_cython '

1 个答案:

答案 0 :(得分:0)

公平警告:这是一种对我有效的解决方法,可能对您不起作用。尽管我不知道发生此问题的原因,但在此处发布了解决方法,但希望此问题能够暂时解决。

我也遇到Spacy == 2.2.3的相同问题。我还打开了一个issue on Spacy repo

从我读到的书中,我知道如果另一个库已经使用另一个(读取的较低版本)的Cython进行编译,则可能会引起一些问题。我不确定原因和方式。

但是经过一些反复试验,我将spacy降级为2.1.3(Spacy == 2.1.3),它的工作原理很吸引人。

相关问题