Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Hadoop和NLTK:使用stopwords失败_Python_Hadoop_Mapreduce_Cluster Analysis - Fatal编程技术网

Python Hadoop和NLTK:使用stopwords失败

Python Hadoop和NLTK:使用stopwords失败,python,hadoop,mapreduce,cluster-analysis,Python,Hadoop,Mapreduce,Cluster Analysis,我正在尝试在Hadoop上运行Python程序。该计划涉及NLTK库。如前所述,该程序还利用Hadoop流API mapper.py: #!/usr/bin/env python import sys import nltk from nltk.corpus import stopwords #print stopwords.words('english') for line in sys.stdin: print line, #!/usr/bin/env python

我正在尝试在Hadoop上运行Python程序。该计划涉及NLTK库。如前所述,该程序还利用Hadoop流API

mapper.py:

#!/usr/bin/env python
import sys
import nltk
from nltk.corpus import stopwords

#print stopwords.words('english')

for line in sys.stdin:
        print line,
#!/usr/bin/env python

import sys
for line in sys.stdin:
    print line,
bin/hadoop jar contrib/streaming/hadoop-streaming.jar \ -file /hadoop/mapper.py -mapper /hadoop/mapper.py -file /hadoop/reducer.py -reducer /hadoop/reducer.py -input /hadoop/input.txt -output /hadoop/output
reducer.py:

#!/usr/bin/env python
import sys
import nltk
from nltk.corpus import stopwords

#print stopwords.words('english')

for line in sys.stdin:
        print line,
#!/usr/bin/env python

import sys
for line in sys.stdin:
    print line,
bin/hadoop jar contrib/streaming/hadoop-streaming.jar \ -file /hadoop/mapper.py -mapper /hadoop/mapper.py -file /hadoop/reducer.py -reducer /hadoop/reducer.py -input /hadoop/input.txt -output /hadoop/output
控制台命令:

#!/usr/bin/env python
import sys
import nltk
from nltk.corpus import stopwords

#print stopwords.words('english')

for line in sys.stdin:
        print line,
#!/usr/bin/env python

import sys
for line in sys.stdin:
    print line,
bin/hadoop jar contrib/streaming/hadoop-streaming.jar \ -file /hadoop/mapper.py -mapper /hadoop/mapper.py -file /hadoop/reducer.py -reducer /hadoop/reducer.py -input /hadoop/input.txt -output /hadoop/output
这运行得很好,输出只包含输入文件的行

但是,当此行(来自mapper.py)时:

#打印停止字。字('english')

如果未注释,则程序失败并显示

工作不成功。错误:#超过允许的失败映射任务数 限度失败计数:1

我已经检查并在一个独立的python程序中

打印停止字。字('english')

它工作得非常好,所以我完全不明白为什么它会导致我的Hadoop程序失败


我将非常感谢任何帮助!谢谢

使用以下命令解压:

importer = zipimport.zipimporter('nltk.zip')
    importer2=zipimport.zipimporter('yaml.zip')
    yaml = importer2.load_module('yaml')
    nltk = importer.load_module('nltk')

检查我贴在上面的链接。他们已经提到了所有的步骤。

打印stopwords.words('english')
中,“english”是一个文件吗?如果是,您也需要使用
-file
将其跨节点发送。

hadoop目录中没有ntlk语料库。试试这个也试试这个---@user1525721谢谢你的回复。将尝试并发回。如果我在所有节点上都有NLTK,这仍然是必要的吗?您可以提供映射器n reducer的路径。同样,您必须指出python库才能使用它。@user1525721感谢您的澄清。另一个问题——为什么nltk.corpus的
导入stopwords不会导致失败?我需要在控制台命令中发送这些文件,还是将它们存储在每台机器的本地?另外,我需要nltk.zip还是nltk_data.zip?我怎样才能找到前者?yaml在这方面扮演什么角色?谢谢我已经尝试了你的建议,并且已经导入了nltk和yaml,没有任何问题。然而,我仍然无法让停止语起作用<代码>从nltk.corpus导入stopwords
不会导致程序失败,但只要我键入
打印stopwords.words('english')
,它就会失败。知道怎么修理吗?我已经在控制台命令中包含了这个命令:
-archives./stopwords.zip
谢谢!