knime workflow errors in python

Hi knime community,

I am a novice at knime and am currently facing some issues.
I would like to request your assistance in resolving my issues with running knime inside my python notebook. I am currently trying 2 approaches, both of which are not working so far. Seeking help from experts please.

I am trying to use this workflow that I downloaded: GitHub - kmansouri/QSAR-ready: Standardization workflow for QSAR-ready chemical structures pre-treatment. See "release" tab for the latest version and sample files!. It works when I run it inside knime itself, but I am trying to see if I can run it inside python notebooks.

I would like to seek your assistance in solving these errors. Thank you in advance!

I have detailed the 2 methods below.

Best,

Marcus

  1. In the first approach, I ran pip install for knime and I am trying to run the workflow in this way, however I am not sure how to run the command.
df_ld50.head()

df_ld50 = pd.read_csv(r"C:\Users\TechD\Documents\Marcus\screening\src\data\raw\knime\knime_input_rat_oral_ld50.csv")

# Initialize workflow

with knime.Workflow(knime_workflow_path) as wf:

wf.data_table_inputs[0] = df_ld50[]

wf.execute()

if len(wf.data_table_outputs) == 0:

raise ValueError("The workflow does not have any output ports. Please add an output port to the workflow.")

# Retrieve output data from the first output port

output_table = wf.data_table_outputs[0]

print(output_table)

Here is what the dataframe looks like and here are the errors I encountered:

In the second approach, I tried running the subprocess. However it appears that no matter what I try, the input file path is not the file I specify. Please see the highlighted part in the screenshot below


command = [

executable_path,

"-reset",

"-nosplash",

"-nosave",

"-application", "org.knime.product.KNIME_BATCH_APPLICATION",

f"-workflowDir={knime_workflow_path}",

f'-workflow.variable=cmd_input,{input_file_path},String'

]

result = subprocess.run(command, capture_output=True, text=True)

# Check for errors

if result.returncode != 0:

print("KNIME workflow execution failed.")

print("STDOUT:", result.stdout)

print("STDERR:", result.stderr)

else:

print("KNIME workflow executed successfully.")

print("Output:", result.stdout)

@MCHR_CHR you can run knime from Jupyter notebooks

1 Like

Hi @mlauber71 thank you so much for your reply.

I am new to knime and am not sure how to follow your instructions. The subprocess method seems to at least be showing me some results. would you be able to help me debug that method?

specifically why I the following code is not processing the correct input I specify and using the default file input.

knime_workflow_path = r"C:\Users\TechD\Documents\Marcus\knime\knime_4.5.1\knime-workspace\QSAR-ready_2.5.8" # absolute path
executable_path = r"C:\Users\TechD\Documents\Marcus\knime\knime_4.5.1\knime.exe"
input_file_path = r"C:\Users\TechD\Documents\Marcus\src\data\raw\test_knime\input.csv"
command = [
    executable_path,
    "-reset",
    "-nosplash",
    "-nosave",
    "-application", "org.knime.product.KNIME_BATCH_APPLICATION",
    f'-workflowDir={knime_workflow_path}',
    f'-workflow.variable=cmd_input,"{input_file_path}",String'
]
result = subprocess.run(command, capture_output=True, text=True)

You see from this line in the output that it is not using the correct file
WARN KNIME-Worker-34-Table Column to Variable 0:8:0:3637 Node No such file: "C:\Users\mansourik2\Downloads\Sample_input.sdf"