带有Jython/Pig的python UDF版本 [英] python UDF version with Jython/Pig

查看:128
本文介绍了带有Jython/Pig的python UDF版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用Pig做Python UDF时,我们如何知道它使用的是哪个版本的Python?是否可以使用特定版本的Python?

When I do Python UDF with Pig, how do we know which version of Python it is using? Is it possible to use a specific version of Python?

具体来说,我的问题出在我的UDF中,我需要在数学模块math.erf()中使用一个函数,该函数是Python 2.7版中新引入的.我已经在计算机上安装了Python 2.7,并且独立的Python程序运行良好,但是当我在Pig中以Python UDF的身份运行它时,我得到了:

Specifically my problem is in my UDF, I need to use a function in math module math.erf() which is newly introduced in Python version 2.7. I have Python 2.7 installed on my machine and standalone Python program runs fine but when I run it in Pig as Python UDF, I got this:

AttributeError:类型对象'org.python.modules.math'没有属性'erf'

AttributeError: type object 'org.python.modules.math' has no attribute 'erf'

我的猜测是Jython使用的是2.7之前的Python版本?

My guess is Jython is using some pre-2.7 version of Python?

感谢您的帮助!

推荐答案

要获取您正在使用的版本,可以执行以下操作:

To get the version you are using you can do this:

myUDFS.py

#!/usr/bin/python

import sys

@outputSchema('bar: chararray')
def my_func(foo):
    print sys.version
    return foo

如果您在本地运行脚本,则该版本将直接打印到stdout.要在远程运行sys.version时查看其输出,必须检查作业跟踪器上的日志.

If you run the script locally then the version will be printed directly to stdout. To see the output of sys.version when you run it remotely you'll have to check the logs on the job tracker.

但是,您对Jython早于2.7(有点)是正确的.目前,Jython的当前稳定版本是 2.5.3 ,因此这是Pig的版本.使用.有一个2.7的beta版本.

However, you are right about Jython being pre-2.7 (kind of). The current stable version of Jython right now is 2.5.3, so this is the version that Pig is using. There is a beta version of 2.7.

这篇关于带有Jython/Pig的python UDF版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆