2016-02-26 119 views
0

我使用mrjob libaries在python中编码mapreducer。我安装mrjob包,但是当我from mrjob.step import MRStep它出现错误:ImportError:No module named step

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

任何人都可以帮我吗?非常感谢

+0

概率很好,因为mrjob.job中没有mrjob – dnit13

+0

里面没有模块或文件import MRJob work fine,bro。 – NoobFromVN

+0

不是。它的语法无效,@ R.Murray。我遵循教程,我看到它工作正常。不同的事情只是他们使用窗口和我使用的Ubuntu的 – NoobFromVN

回答

0

大家好,我解决了这个问题,这里是字数的工作代码。基本上,一个简单的替换对我有效。

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) 
    ] 

从mrjob.job进口MRJob 进口重新

WORD_RE = re.compile(R “[\ W'] +”)

类MRMostUsedWord(MRJob)

如果 == '主要': MRMostUsedWord.run()

相关问题