为什么在执行python脚本时会出现No这样的文件或目录错误?

时间:2012-11-15 12:39:01

标签: python hadoop hadoop-streaming

  

可能重复:
  ubuntu /usr/bin/env: python: No such file or directory

我是hadoop流媒体的新学习者。我遇到了学习mapreduce的问题。 这是我的mapper.py代码:

#!/usr/bin/env python 

import sys

# input comes from STDIN (standard input)
for line in sys.stdin:
    # remove leading and trailing whitespace
    line = line.strip()
    # split the line into words
    words = line.split()
    # increase counters
    for word in words:
        # write the results to STDOUT (standard output);
        # what we output here will be the input for the
        # Reduce step, i.e. the input for reducer.py
        #
        # tab-delimited; the trivial word count is 1
        print '%s\t%s' % (word, 1)

执行以下操作时:

hadoop@Chris-ubuntu:/home/test$ echo "I love China I love ieee I love python" | /home/test/mapper.py 

我得到了结果:

: No such file or directory

但是,我确信该文件确实存在于该路径中,ls可以看到该文件。所以我想知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

默认情况下Python文件不可执行,因此您必须告诉python解释器运行您的文件:

echo "I love China I love ieee I love python" | python2 /home/test/mapper.py

或者,您可以输入以下命令使文件可执行: chmod +x mapper.py 然后运行

echo "I love China I love ieee I love python" | /home/test/mapper.py

相关问题