如何在Nifi中的虚拟环境中运行具有依赖性的python脚本? [英] How to run a python script with dependencies in a virtual environment in Nifi?

查看:557
本文介绍了如何在Nifi中的虚拟环境中运行具有依赖性的python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Nifi中是否有一种方法可以运行python脚本,该脚本具有从其他文件夹导入的模块,在pipfile中指定的要求以及要传递的参数?

Is there a way in Nifi to run a python script which has modules imported from a different folder, requirements specified in a pipfile and has arguments to pass?

简而言之,如何使用Nifi执行通常在我的虚拟环境中运行的python脚本?

In short, how to execute a python script which usually runs in my virtual environment using Nifi?

我的最终目标是使用获取文件"来拾取文件并将其发布到API.我尝试执行过程,执行流命令处理器.

The end goal for me is to pick up a file using Get File and post it to API. I tried execute process, execute streamcommand processors.

推荐答案

要使用Python对流文件执行后续处理,可以使用ExecuteStreamCommandExecuteScript/InvokeScriptedProcessor处理器.

To perform follow-on processing on the flowfile using Python, you can use the ExecuteStreamCommand or ExecuteScript/InvokeScriptedProcessor processors.

此答案.

The ExecuteStreamCommand processor will run an external shell command, like python3 my_python_script.py -arg1 string -arg2 213, which can wrap custom Python code and uses STDIN to pass the existing flowfile content and STDOUT to capture the new flowfile content. Populate the Command Arguments and Command Path properties of the processor to locate your python executable and provide CLI arguments, including flowfile attributes via NiFi Expression Language. See this answer for an example.

此答案此答案了解更多信息.

The ExecuteScript processor runs Jython code (Python but without access to native libraries, only Python 2.7 compatibility, and some other restrictions due to JSR-223) in the same JVM as NiFi. You can process the flowfile attributes and content directly with Python code. See this answer or this answer for more details.

这篇关于如何在Nifi中的虚拟环境中运行具有依赖性的python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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