【问题标题】:No module named simplejson in python UDF on EMREMR 上的 python UDF 中没有名为 simplejson 的模块
【发布时间】:2015-05-31 17:25:03
【问题描述】:

我正在使用 Pig 运行 Amazon Elastic 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

但是,我的 Amazon AMI 包含 Python 2.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 环境的方式肯定有所不同,但又是什么?

【问题讨论】:

    标签: amazon-web-services apache-pig elastic-map-reduce


    【解决方案1】:

    Pig UDF 使用 jython,它不适用于 simplejson。

    您可以尝试: Jyson 作为 Json 解析器

    【讨论】:

    • 谢谢 我不知道!我会检查一下。
    猜你喜欢
    • 1970-01-01
    • 2011-02-05
    • 2018-12-18
    • 2012-06-08
    • 1970-01-01
    • 2015-01-11
    • 2020-02-07
    • 2019-12-10
    • 1970-01-01
    相关资源
    最近更新 更多