Python Script Execute failed: Could not connect to the Python process.

Hi,
I’d like to use the new Python Script node, but, unlike the previous one (Legacy), it doesn’t work, see message below.
Some idea?

Python Script ERROR 3:10 Execution failed: Unable to connect to Python process.

Thanks,
Alfredo





Hello @alfroc
You are right; the Py coding for referencing data input from KNIME to pandas, and sending it to the output port changed from legacy nodes.

You can test with the following code as starting point:

import knime.scripting.io as knio
import pandas as pd

# data in
df = knio.input_tables[0].to_pandas()

# things happen
print(type(df))

# output as pd.DataFrame
knio.output_tables[0] = knio.Table.from_pandas(df)

BR

PS.- The equivalent code for your Py code example would be:

import knime.scripting.io as knio
import pandas as pd

# Copy input to output
knio.output_tables[0] = knio.Table.from_pandas(knio.input_tables[0].to_pandas())

Also note: If you want to use a conda env different to the main env you have configured for KNIME to use in general, you will need to select this.

In your example the conda environment propagation node creates the following variable:

You need to go to configure flow variables of Python Script node:

image

And then select it from the drop down:

image

If you can’t see that variable there are from my experience two reasons:

  1. sometimes seems a bit inconsistent - even if conda node is executed the variable doesnt show. In those cases: Save workflow and re-open and check again - when taking the above screenshot I had to do that and then the variable showed
  2. Your custom env has not been created correctly. You can refer to the official docs: KNIME Python Integration Guide
    or follow one of the articles on medium:
2 Likes

Hi @gonhaddock,
unfortunally it doesn’t worlk.
Cheers,
Alfredo

Python_Server_Error.knwf (19.9 KB)

Hi @MartinDDDD ,
the flow variable was already configured…
The strange thing is that the Python Script (Legacy) node works, moreover without the need for the Conda Environment Propagation one. How do you explain it?
Cheers,
Alfredo

Thanks for providing the workflow!

I checked the env that you are using and honestly to me it looks like it has not been created properly - e.g. knime-python-scripting package seems to be missing:

I’m afraid I can’t explain why it is working in Legacy Node.

I’d suggest that to make sure the env you are using works that you create a new one and start with the command as shown in the documentation linked above… then add your packages to it as you see fit.

conda create --name my_python_env -c knime -c conda-forge knime-python-scripting=5.3 python=3.11 

Change “my_python_env” to a name of your liking.

2 Likes

Thanks for all the suggestions, @MartinDDDD, but since the legacy node works, I’ll continue using that.
Cheers,
Alfredo

1 Like

Hello @alfroc
What I see from your previous captures is that maybe the error comes from your Py version 3.6 , it seems that this version doesn’t support KNIME Python Integration. You probably need to reinstall/update all your Conda environment to a minimum Py version 3.9

“The KNIME Python Integration works with Python versions 3.9 to 3.11 and comes with a bundled Python environment to let you start right away. This convenience allows to use the nodes without installing, configuring or even knowing environments. The included bundled Python environment comes with these packages.”

# KNIME Python Integration Guide

Please find an attached workflow that is working for me in this computer (currently failing at some Py based nodes), so consider these as a minimum to make it work.

KNIME 4.7.2
Conda version 23.3.1
Python version 3.9.16

20240718_output_data_using_Py_v0.knwf (19.6 KB)

BR

PS.- I’m reposting this post from editing, as I deleted the post by mistake when copying the link… there isn’t chace to undo this action.

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