Using a python library in a node.

Hey there,

I am creating a node which may require the use of a python library, as i cannot find a similar one in java.

I am thinking i may use Jython to do this. Is this possible in KNIME?

Is there a better solution to this at all?

I appreciate your help :slight_smile:

1 Like

Hi @toblatp,
You can definitely use Jython as a dependency for a node, in fact there are some (legacy) Jython scripting nodes somewhere in KNIME. The question is whether the library will work correctly in Jython, which it might not if it depends on native code.

An alternative is to use a Python scripting node and code your functionality as a python script (requires you to install the library in your python environment). This is more difficult to distribute though.

Can you tell me which python library you need ? Maybe I know a java alternative.


Hey Gabriel,

Thanks for your help, sorry I have been slow to reply to this one. Awesome, I will have a think about a solution to this, yes I think the tricky part is for distributing the python library. Its a library for writing to a niche data format, imzML, and I think it is only available in python.

Thanks for your help!

If the library you are using is available via pip you can add a node that ensures it is installed to your workflow, e.g. via a Python Edit Variable node with the following code:

# create flow variable named random with 0 <= value <= 100
from pandas import DataFrame
import subprocess
import sys

def install(package):[sys.executable, "-m", "pip", "install", "--user", package])


flow_variables['installed'] = "true"


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.