Failed to parse Python node extension

Hi KNIMErs,

I am struggling to connect my pure-Python extension running on Python 3.11 and conda 23.5.2 with my KAP v4.7 in debug mode.

This is an excerpt of my extension’s folder structure:

KNIME
|__ config.yml
|__ test_extension
    |__ knime.yml
    |__ conda_env.yml
    |__ test_nodes.py
    |__ LICENSE.txt

When starting KAP, it throws this exception:

ERROR PurePythonNodeSetFactory            Failed to parse Python node extension at path 'path/to/KNIME/test_extension'.

‘path/to/KNIME/test_extension’ is the path specified in my config.yml’s src key-value pair.

The KNIME logs show that this is due to the following problem of importlib:

ModuleNotFoundError: No module named 'test_nodes.py'; 'test_nodes' is not a package

‘test_nodes.py’ is the value assigned to the extension_module key in knime.yml.

The error persists despite having added the KNIME and KNIME/test_extension folders (with and without empty __init__.py files) to sys.path of my conda environment ‘knime_dev’ (as per conda_env_path in config.yml) via either of the following methods:

  • a .pth file in ./opt/miniconda3/envs/knime_dev/lib/python3.11/site-packages
  • putting the entire project folder in ./opt/miniconda3/envs/knime_dev/lib/python3.11/site-packages

What am I missing here to point KNIME to my test_nodes.py file?

The information that I am sharing with you above are from a Mac, but I face the exact same issue on Windows too. So, I am looking to fix this on both systems. Please note that I do not have admin rights on the Windows machine.

Cheers!

@DerMaxdorfer I can offer this example how to import one’s own module. Maybe you can test and take it from there:

Thanks for the example workflow, @mlauber71. I appreciate your support on the weekend! :wink:

Your call to sys.path.append() is basically the same as me adding a .pth file to a conda env, with the following two differences:

  • Paths listed in a .pth file are available from the startup of the Python instance
  • Paths are not removed after the script has finished running

The question that remains for me is which is the correct path to append to sys.path so that KAP finds the .py file with my nodes?

As my case is not with a particular workflow and Python Script nodes, but an entire extension, I do not have a workflow directory because KAP runs in to the described error before I even get the chance to open a workflow.

Hi @DerMaxdorfer,

it looks like KAP already knows of the existence of your extension and where to find it.
I suspect that knime.yml is not pointing correctly to test_nodes.py.

Could you

  1. Provide the line extension_module in your knime.yml?
  2. Verify that it looks like this: extension_module: test_nodes :wink:
  3. Have another look at the setup of knime.yml
  4. If the issue persists: provide the whole section of the KNIME Log regarding the issue

Best regards
Steffen

1 Like

You are spot-on, @steffen_KNIME!

I had it like this in my file: extension_module: test_nodes.py. It is pretty obvious now that this key-value pair does not take the filename extension given that you even named the key extension_module and not extension_file. :man_facepalming: I must have overlooked it in the documentation because env_yml_path and license_file seem to require their respective ones indeed.

And it is not necessary to append anything to sys.path myself. KNIME is smart enough to find the extension anywhere on my machine. :wink:

1 Like

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