emr上pythonudf中没有名为simplejson的模块

vhipe2zx  于 2021-06-25  发布在  Pig
关注(0)|答案(1)|浏览(261)

我正在使用pig运行amazon弹性mapreduce(emr)作业。我在将json或simplejson模块导入python用户定义函数(udf)时遇到问题。
这是我的密码:


# !/usr/bin/env python

import simplejson as json
@outputSchema('m:map[]')
def flattenJSON(text):
    j = json.loads(text)
    ...

当我尝试在pig中注册函数时,我得到一个错误,上面写着“没有名为simplejson的模块”

grunt> register 's3://chopperui-emr/code/flattenDict.py' using jython as flatten;
2015-05-31 16:53:43,041 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1121: Python Error. Traceback (most recent call last):
File "/tmp/pig6071834754384533869tmp/flattenDict.py", line 32, in <module>
import simplejson as json
ImportError: No module named simplejson

但是,我的amazonami包含python2.6,其中包含json作为标准包(使用import json也不起作用)。另外,如果我尝试使用pip安装simplejson,它会说它已经安装(在主节点和核心节点上)。

[hadoop@ip-172-31-46-71 ~]$ pip install simplejson
Requirement already satisfied (use --upgrade to upgrade): simplejson in /usr/local/lib64/python2.6/site-packages

另外,如果我从主节点上的命令行以交互方式运行python,它也可以正常工作

[hadoop@ip-172-31-46-71 ~]$ python
Python 2.6.9 (unknown, Apr  1 2015, 18:16:00) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>>

emr或pig设置python环境的方式肯定有些不同,但是什么呢?

lvmkulzt

lvmkulzt1#

pig-udf使用jython,而jython不适用于simplejson。
您可以尝试:jyson作为json解析器

相关问题