简体   繁体   English

无法从Nifi ExecuteScript处理器引用python库

[英]Unable to refer python libraries from Nifi ExecuteScript processor

I have been trying to run a python script in NiFi's ExecuteScript processor. 我一直在尝试在NiFi的ExecuteScript处理器中运行python脚本。 Though the catch here is that I don't have server file location access and all the python libraries are installed at "/data/jython", "/data/jython/Lib/site-packages/" and "data/nltk" 尽管这里的问题是我没有服务器文件位置访问权限,并且所有python库都安装在“ / data / jython”,“ / data / jython / Lib / site-packages /”和“ data / nltk”下

Below is the import section of my python script: 以下是我的python脚本的import部分:

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

I have added path reference to the packages/libraries: 我添加了对软件包/库的路径引用: 在此处输入图片说明

Heres the screenshot of the error message: 以下是错误消息的屏幕截图: 在此处输入图片说明

Is there something I am missing? 我有什么想念的吗? I have referred to another answer here , but couldn't figure out whats wrong with my code. 我在这里提到了另一个答案,但无法弄清楚我的代码有什么问题。

As the other answers state, Apache NiFi's ExecuteScript processor uses Jython , not Python . 在其他答案中,Apache NiFi的ExecuteScript处理器使用Jython而不是Python There is a limitation on the Jython library that it cannot handle native modules (modules that end in .so or are compiled C code, etc.). Jython库有一个限制,即它不能处理本机模块(以.so结尾或已编译的C代码等的模块)。 It is very likely that the pycountry module contains some native module. pycountry模块很可能包含一些本机模块。 You can try a work-around proposed by Matt Burgess on the NiFi Developers Mailing List here . 您可以在此处NiFi开发者邮件列表中尝试Matt Burgess提出的解决方法。

ExecuteScript processor uses its own Jython Engine to execute your python scripts. ExecuteScript处理器使用其自己的Jython引擎执行您的python脚本。 As the libraries which you are importing are not available in NIFI inbuild Jython Engine its throwing error. 由于要导入的库在NIFI inbuild Jython Engine中不可用,因此会引发抛出错误。

SOLUTION: 解:

If python is already installed on our machine with all those libraries (the same machine where your NIFI is installed) you can use that python engine to execute your script. 如果我们的计算机上已经安装了所有这些库(所有安装了NIFI的计算机),则可以使用该python引擎执行脚本。 you can execute your python code using ExecuteProcess processor. 您可以使用ExecuteProcess处理器执行python代码。 see the configuration of ExecuteProcess . 请参阅ExecuteProcess的配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM