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

查看:32
本文介绍了带有 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: type object 'org.python.modules.math' 没有属性 'erf'

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

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

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

如果您在本地运行脚本,那么版本将直接打印到标准输出.要在远程运行时查看 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 的测试版.

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天全站免登陆