【问题标题】:Unable to refer python libraries from Nifi ExecuteScript processor无法从 Nifi ExecuteScript 处理器引用 python 库
【发布时间】:2018-01-11 15:41:12
【问题描述】:

我一直在尝试在 NiFi 的 ExecuteScript 处理器中运行 python 脚本。虽然这里的问题是我没有服务器文件位置访问权限,并且所有 python 库都安装在“/data/jython”、“/data/jython/Lib/site-packages/”和“data/nltk”

下面是我的python脚本的导入部分:

import json, traceback, pycountry, requests, geocoder, re, sys, nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
from nltk.corpus import stopwords
from java.nio.charset import StandardCharsets
from org.apache.commons.io import IOUtils
from org.apache.nifi.processor.io import StreamCallback
from org.python.core.util import StringUtil

我添加了对包/库的路径引用:

错误信息截图如下:

我有什么遗漏吗?我参考了另一个答案here,但无法弄清楚我的代码有什么问题。

【问题讨论】:

    标签: python apache-nifi


    【解决方案1】:

    正如其他答案所述,Apache NiFi 的 ExecuteScript 处理器使用 Jython,而不是 Python。 Jython 库有一个限制,它不能处理本机模块(以 .so 结尾的模块或编译后的 C 代码等)。 pycountry 模块很可能包含一些本地模块。您可以尝试由 Matt Burgess 在NiFi Developers Mailing List here 上提出的解决方法。

    【讨论】:

    • 我尝试使用 sys.path.append() 添加库路径。还尝试添加模块目录的路径,但没有成功。
    • 正如@Andy 上面所说,您正在使用的一些模块正在使用本机编译的代码。见mattyb的回答here
    【解决方案2】:

    ExecuteScript 处理器使用自己的 Jython 引擎来执行您的 python 脚本。 由于您要导入的库在 NIFI inbuild Jython Engine 中不可用,因此引发错误。

    解决方案:

    如果我们的机器上已经安装了 python 以及所有这些库(安装了 NIFI 的同一台机器),您可以使用该 python 引擎 执行你的脚本。您可以使用 ExecuteProcess 处理器执行您的 python 代码。 see the configuration of ExecuteProcess.

    【讨论】:

      猜你喜欢
      • 2019-10-12
      • 2016-08-30
      • 1970-01-01
      • 2020-03-01
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      相关资源
      最近更新 更多