RUNNING KNIME USING PYTHON [KNIMEPY]

Hi All!

The following codes are working and seem to be running KNIME workflow but are not really producing the output excel file:

please help to amend the python code so that it is able to execute this workflow and successfully produce the output file (which is my check to see if the python code execution is successful…)

{I am attaching a very simple iris data workflow where you will have to adjust excel output file path to your local drive}

Thanks
CODE 1:
import knime
knime.executable_path = r"C:\Users\fatima.s\Portable Knime\knime_4.2.5\knime.exe"
with knime.Workflow(r"C:\Users\fatima.s\knime-workspace\Example Workflows\Python View Example") as wf:
wf.execute()

Python View Example.knwf (11.5 KB)

CODE 2:
import knime
knime.executable_path= r"C:\Users\fatima.s\Portable Knime\knime_4.2.5\knime.exe"
workflow= r"C:\Users\fatima.s\knime-workspace\Example Workflows\Python View Example"
workspace= r"C:\Users\fatima.s\knime-workspace"

#knime.executable_path= “C:/Users/fatima.s/Portable Knime/knime_4.2.5/knime.exe”
#workflow= “C:/Users/fatima.s/knime-workspace/Example Workflows/Python View Example”
#workspace= “C:/Users/fatima.s/knime-workspace”
with knime.Workflow(workflow_path=workflow,workspace_path=workspace) as wf:
wf.execute()

@sayedafatima I think the problem is that in your construct there is no iris dataset and no path where to find it. I set up an example that you could adapt:

In the subfolderf /script/ you also find a Jupyter Notebook where you would be able to test the code

3 Likes

Dear [mlauber71]:
Thank you for your reply and your valuable input
The problem is not the workflow or its execution via knime;
when the workflow is executed on KNIME, it works perfectly and produces the excel output file.
[Hence, there is no problem with this dummy workflow itself.]
However, the query is how to access and run the workflow via python script.
The goal is not to produce the image but just to execute this workflow so that it produces the desired excel file.
So I tried the following codes in Jupiter notebook using Anaconda Navigator which seems to execute the workflow but doesn’t produces the excel file.
This suggests that although the workflow is loaded correctly but is not being executed properly.
Hence, the query is simply to execute the same workflow using python code which is working fine manually.
Please also see the following links which were used to build the code:
[note that unlike the workflows in links, our workflow does not require any input ports]
I have removed the python View node from workflow since the goal was not to produce a image or chart.
Gladly, I myself solved it with amended code below:
import knime
knime.executable_path= r’C:\Users\fatima.s\Portable Knime\knime_4.2.5\knime.exe’
workflow= r’c:\Users\fatima.s\knime-workspace\Example Workflows\Python View Example’
workspace= r’C:\Users\fatima.s\knime-workspace’
with knime.Workflow(workflow_path=workflow,workspace_path=workspace) as wf:
wf.execute()Python View Example.knwf.knar (10.6 KB)

Thanks again for your assistance.

2 Likes

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