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

cdmah0mi  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(275)

这个问题在这里已经有答案了

8年前关门了。
可能重复:
ubuntu/usr/bin/env:python:没有这样的文件或目录
我是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 . 所以我只是想知道如何才能解决这个问题。

0wi1tuuw

0wi1tuuw1#

默认情况下,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

相关问题