使用python MRJob在EMR上引导库

时间:2014-05-03 05:15:26

标签: python hadoop nltk emr mrjob

问题陈述:

我正在尝试使用python MRJob库在Amazon EMR中运行map-reduce作业,而我在使用必需的库和包引导节点时遇到了麻烦。

详细说明:

我的示例python mrjob代码:

    import re
    from mrjob.job import MRJob
    from sentClassifier import sentClassify
    import nltk

    .. do something ..

有一些像NLTK这样的库需要导入,我导入的一些本地模块就像from sentClassifier import sentClassify

我想知道引导EMR节点的最佳方法是什么,以便这些方法和包可用。代码在我的本地机器上运行良好。

我的样本mrjob.conf文件:

    runners:
      emr:
        aws_access_key_id: ***
        aws_secret_access_key: ***
        ec2_core_instance_type: m1.large
        ec2_key_pair: mykey
        ec2_key_pair_file: mykey.pem
        num_ec2_core_instances: 5
        pool_wait_minutes: 2
        pool_emr_job_flows: true
        ssh_tunnel_is_open: true
        ssh_tunnel_to_job_tracker: true
      hadoop:
        setup:
          - virtualenv venv
          - . venv/bin/activate
          - pip install mr3po simplejson
          - sudo easy_install https://code.google.com/p/nltk/downloads/detail?name=nltk-2.0b9-py2.6.egg&can=2&q=

但是工作失败了。

我已阅读以下参考资料并尝试了各种方法,但仍然没有运气:

错误日志:

    Scanning SSH logs for probable cause of failure
    Probable cause of failure (from ssh://ec2-54-86-50-115.compute-1.amazonaws.com!172.31.19.60/mnt/var/log/hadoop/userlogs/job_201405030101_0006/attempt_201405030101_0006_m_000002_3/stderr):
    Traceback (most recent call last):
    File "obidroidMR.py", line 5, in <module>
       import nltk
       ImportError: No module named nltk
       (while reading from s3://mrjob-   51b9493c1a467671/tmp/obidroidMR.shreyas.20140503.012933.336228/files/STDIN)
       Attempting to terminate job...
       Job appears to have already been terminated
       Killing our SSH tunnel (pid 12909)
       Traceback (most recent call last):
         File "obidroidMR.py", line 107, in <module>
         ObidroidReview.run()
         File "/Users/shreyas/anaconda/envs/obidroid/lib/python2.7/site-packages/mrjob/job.py", line 494, in run
         mr_job.execute()
         File "/Users/shreyas/anaconda/envs/obidroid/lib/python2.7/site-packages/mrjob/job.py", line 512, in execute
super(MRJob, self).execute()
         File "/Users/shreyas/anaconda/envs/obidroid/lib/python2.7/site-packages/mrjob/launch.py", line 147, in execute
         self.run_job()
         File "/Users/shreyas/anaconda/envs/obidroid/lib/python2.7/site-packages/mrjob/launch.py", line 208, in run_job
runner.run()
         File "/Users/shreyas/anaconda/envs/obidroid/lib/python2.7/site-packages/mrjob/runner.py", line 458, in run
self._run()
         File "/Users/shreyas/anaconda/envs/obidroid/lib/python2.7/site-packages/mrjob/emr.py", line 809, in _run
         self._wait_for_job_to_complete()
         File "/Users/shreyas/anaconda/envs/obidroid/lib/python2.7/site-packages/mrjob/emr.py", line 1599, in _wait_for_job_to_complete
         raise Exception(msg)
         Exception: Job on job flow j-2R8G1Q3RIE9ED failed with status WAITING: Waiting after step failed
         Probable cause of failure (from ssh://ec2-54-86-50-115.compute-1.amazonaws.com!172.31.19.60/mnt/var/log/hadoop/userlogs/job_201405030101_0006/attempt_201405030101_0006_m_000002_3/stderr):
         Traceback (most recent call last):
         File "obidroidMR.py", line 5, in <module>
         import nltk
         ImportError: No module named nltk

任何帮助都会非常感激

2 个答案:

答案 0 :(得分:2)

mrjob.conf中,安装软件包所需的行可能不在应有的位置。应该在EMR上运行的作业应该应用的内容应该列在emr:而不是hadoop:下(这是在本地Hadoop安装上运行作业时的配置。

如果它是一个简单的Linux命令,如pipapt-get,那么您应该可以像这样安装软件包:

runners:
  emr:
    aws_access_key_id: ***
    ... all the other stuff ...
    bootstrap_cmds:
    - sudo apt-get install -y python-boto
    - sudo pip install simplejson

我从未尝试过专门安装NLTK,所以我无法帮助你,但你应该可以沿着这条线安装。

对于可能更复杂的安装,我建议使用EMR CLI ssh进入主节点:

$ ./elastic-mapreduce -j JOB_FLOW_ID --ssh

并实际尝试安装包。如果您找到一系列成功安装软件包的shell命令,那么您只需将其复制并粘贴到mrjob.conf即可。

答案 1 :(得分:0)

鉴于Amazon Elastic Map Reduce使用AMI based on Amazon Linux,我确认可以使用以下

在Amazon Linux AMI 2014.03.1 - ami-fb8e9292(64位)上安装nltk
sudo easy_install -U pip
sudo easy_install -U distribute
sudo pip install -U pyyaml nltk

您可以尝试将这3行合并到mrjob.conf