导入错误:没有名为步骤的模块



我正在用python编写mapreducer,使用mrjob libaries。我安装了mrjob软件包,但是当我from mrjob.step import MRStep时出现错误:

    from mrjob.step import MRStep
ImportError: No module named step

有人可以帮助我吗?非常感谢

大家好,我解决了这个问题,这是字数统计的工作代码。从本质上讲,一个简单的替换对我有用。

从 mrjob.job import MRJob进口再

WORD_RE = re.compile(r"[\w']+")

类MRMostUsedWord(MRJob):

def mapper_get_words(self, _, line):
    # yield each word in the line
    for word in WORD_RE.findall(line):
        yield (word.lower(), 1)
def combiner_count_words(self, word, counts):
    # sum the words we've seen so far
    yield (word, sum(counts))
def reducer_count_words(self, word, counts):
    # send all (num_occurrences, word) pairs to the same reducer.
    # num_occurrences is so we can easily use Python's max() function.
    yield None, (sum(counts), word)
# discard the key; it is just None
def reducer_find_max_word(self, _, word_count_pairs):
    # each item of word_count_pairs is (count, word),
    # so yielding one results in key=counts, value=word
    yield max(word_count_pairs)
def steps(self):
    return [
        self.mr(mapper=self.mapper_get_words,
               combiner=self.combiner_count_words,
               reducer=self.reducer_count_words),
        self.mr(reducer=self.reducer_find_max_word)
    ]

如果名称 == 'main': MRMostUsedWord.run()

相关内容

  • 没有找到相关文章

最新更新