AttributeError:无法从'manage.py'>获取<模块'__main__'上的属性 [英] AttributeError: Can't get attribute on <module '__main__' from 'manage.py'>

查看:662
本文介绍了AttributeError:无法从'manage.py'>获取<模块'__main__'上的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

def getNer(text):
    with open('chunker.pkl', 'rb') as pickle_file:
        chunker = pickle.load(pickle_file)
    return chunker.parse(pos_tag(word_tokenize(text)))

运行此功能有效罚款
,但是当我在Django项目
中包含此函数时,出现以下错误

Running this function works fine But when I include this function in my Django Project I get the following error

chunker = pickle.load(pickle_file)
AttributeError: Can't get attribute 'NamedEntityChunker' on <module '__main__' from 'manage.py'>

被腌制的物体是

class NamedEntityChunker(ChunkParserI):
    def __init__(self, train_sents, **kwargs):
        assert isinstance(train_sents, Iterable)

        self.feature_detector = features
        self.tagger = ClassifierBasedTagger(
            train=train_sents,
            feature_detector=features,
            **kwargs)

    def parse(self, tagged_sent):
        chunks = self.tagger.tag(tagged_sent)
        iob_triplets = [(w, t, c) for ((w, t), c) in chunks]
        return conlltags2tree(iob_triplets)

我使用最新版本的Django和Python3

Im using the latest version of Django and Python3

推荐答案

我遇到了同样的错误-事实证明,在尝试打开类之前,我没有导入该类。 GUI必须先知道如何构造对象才能读取它。尝试:

I had the same error - turns out I wasn't importing the class before trying to open it. The GUI needs to know how to construct the object before being able to read it. Try:

from YourModuleName import NamedEntityChunker

,然后调用您的打开函数。

before calling your opening function.

这篇关于AttributeError:无法从'manage.py'&gt;获取&lt;模块'__main__'上的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆