我試過使用mrjob更改wordcount示例。我的結構的項目是:無法在Mrjob中導入模塊
├── input_text.txt
├── store_xml_dir
│ ├── xml_file.xml
│ └── xml_parse.py
└── wordcount.py
和內容wordcount.py的是:
import os
import sys
cwdir = os.path.dirname(__file__)
sys.path.append(cwdir)
sys.path.append(os.path.join(cwdir, "store_xml_dir"))
import xml_parse
# print dir(xml_parse) <- it works here if i'd comment the rest code
from mrjob.job import MRJob
class MRWordFrequencyCount(MRJob):
def mapper(self, _, line):
getxml = xml_parse.GetXML()
print '>>>', getxml.get_strings()
yield "chars", len(line)
yield "words", len(line.split())
yield "lines", 1
def reducer(self, key, values):
yield key, sum(values)
if __name__ == '__main__':
MRWordFrequencyCount.run()
當我跑,我有錯誤:ImportError: No module named xml_parse
。爲什麼python在這種情況下無法導入xml_parse
?
您需要在其他節點中放置'store_xml_dir'並將其添加到'pythonpath'。 mrjob不會將您的代碼導出到其他節點。 – Mehraban 2014-10-19 10:29:51
@SAM我通過使用'sys.path.append(os.path.join(cwdir,「store_xml_dir」))附加到'pythonpath'' – Trigges 2014-10-19 10:35:58
似乎mrjob不會在任務跟蹤器上執行該行代碼。也許你需要手動完成。 – Mehraban 2014-10-19 10:38:16