【问题标题】:Running the Python Code on Hadoop Failed在 Hadoop 上运行 Python 代码失败
【发布时间】:2013-02-27 11:53:13
【问题描述】:

我已尝试按照此页面上的说明进行操作: http://www.michael-noll.com/tutorials/writing-an-hadoop-mapreduce-program-in-python/

$bin/hadoop jar contrib/streaming/hadoop-streaming-1.0.4.jar -input /user/root/wordcountpythontxt -output /user/root/wordcountpythontxt-output -mapper /user/root/wordcountpython/mapper.py -reducer /user/root/wordcountpython/reducer.py -file /user/root/mapper.py -file /user/root/reducer.py

它说

File: /user/root/mapper.py does not exist, or is not readable.
Streaming Command Fail

当我浏览 url:jobdetails.jsp/

我发现很多异常

java.lang.RuntimeException: Error in configuring object
    at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:93)
    at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:64)
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:117)
    at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:432)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:372)
    at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:396)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
    at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:88)
    ... 9 more
Caused by: java.lang.RuntimeException: Error in configuring object
    at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:93)
    at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:64)
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:117)
    at org.apache.hadoop.mapred.MapRunner.configure(MapRunner.java:34)
    ... 14 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:88)
    ... 17 more
Caused by: java.lang.RuntimeException: configuration exception
    at org.apache.hadoop.streaming.PipeMapRed.configure(PipeMapRed.java:230)
    at org.apache.hadoop.streaming.PipeMapper.configure(PipeMapper.java:66)
    ... 22 more
Caused by: java.io.IOException: Cannot run program "/user/root/wordcountpython/mapper.py": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
    at org.apache.hadoop.streaming.PipeMapRed.configure(PipeMapRed.java:214)
    ... 23 more
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:53)
    at java.lang.ProcessImpl.start(ProcessImpl.java:91)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
    ... 24 more

我无法修复它,请帮助我运行 python pgm。

【问题讨论】:

    标签: python hadoop-streaming


    【解决方案1】:

    如果您仔细查看了link 上的说明,

    hduser@ubuntu:/usr/local/hadoop$ bin/hadoop jar contrib/streaming/hadoop-*streaming*.jar -file /home/hduser/mapper.py -mapper /home/hduser/mapper.py -file /home/hduser/reducer.py -reducer /home/hduser/reducer.py -input /user/hduser/gutenberg/* -output /user/hduser/gutenberg-output
    

    它清楚地表明不需要将 mapper.py 和 reducer.py 复制到 HDFS,您可以从本地文件系统链接这两个文件:作为 /path/to/mapper。我相信你可以避免上述错误。

    【讨论】:

    • @studhadoop 如果解决方案解决了您的问题,您可以接受答案。谢谢
    【解决方案2】:

    您可能想检查您的 #! 之后是否没有 dos 样式的换行符。 mapper.py 中的行。如果你这样做了,hadoop 可能无法找到你的 python 解释器,因为它会看到一个额外的 CR。例如。 /usr/local/bin/python^M 而不是 /usr/local/bin/python 其中 ^M 是 CR。在你的 mapper 和 reducer 上尝试 dos2unix 命令。

    【讨论】:

    • 我将如何对 mapper 和 reducer 执行此操作
    • ...对不起...只要运行dos2unix mapper.py,假设您安装了dos2unix。然后你的 reducer.py 也是如此。您可以使用 grep 查找 dos 新行以确认它之前存在并之后消失:[stackoverflow.com/questions/73833/….此外,如果这是您的问题,那么您可能会考虑更改编辑器保存文件的方式。例如。如果您使用 Eclipse,则默认为 dos 样式的新行
    【解决方案3】:

    看来问题就出来了。

    Caused by: java.io.IOException: Cannot run program "/user/root/wordcountpython/mapper.py": error=2, No such file or directory
    

    请您检查文件/user/root/wordcountpython/mapper.py 是否存在。如果它存在,那么该文件的权限是什么。

    你运行hadoop的用户有执行和读取这个文件的权限吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      • 2019-03-25
      • 1970-01-01
      • 2018-11-22
      • 1970-01-01
      • 2016-04-11
      相关资源
      最近更新 更多