2012-11-15 710 views
2

可能重複:
ubuntu /usr/bin/env: python: No such file or directory爲什麼執行python腳本時會出現No such file or directory error?

我的hadoop streaming的新學員。我遇到了一個學習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) 

當我執行以下命令:

[email protected]:/home/test$ echo "I love China I love ieee I love python" | /home/test/mapper.py 

我得到的結果是:

: No such file or directory 

不過,我敢肯定,該文件確實存在於該路徑中,可以通過ls看到。所以我只是想知道我該如何解決這個問題。

+6

確實[這個答案](http://stackoverflow.com/questions/3655306/ubuntu-usr-bin-env-python-no-such-file-or-di教區)解決你的問題? –

回答

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

相關問題