Python intregration for Dummies

Hi Knimers!

After a few months learning and practicing Python, I´m back to Knime aiming to test new challenges.

I saw at Knime webpage a way to integrate Knime and Python but I couldn´t had success.

Maybe someone can help me with a step by step for dummies.

ps: The Knime video on You Tube showing how to integrate R and Knime would be perfect :)

 

Thanks again!

Hi Fabio,

Have you already seen our blog post about setting up KNIME & Python? You can find it here.
Please let me know if you already tried the steps described there. I'll gladly help you with some additional information on what to do then.

Marcel

Hi Marcel,

Yes, I saw.

I tried to follow but I´m not that type of user with sympathy for command prompt...if you know what I´m saying :)  

I had stopped at the bat file instruction:

"

If you are using Windows, here’s a sample bat file:

  @REM Adapt the directory in the PATH to your system    
  @SET PATH=C:\tools\Anaconda3\Scripts;%PATH%  
  @CALL activate py35_knime || ECHO Activating py35_knime failed  
  @python %*

"

For R integration was pretty easy and as I started to learn Python this year, I would like to try similar tasks using Knime + Python.

Can you guide me?

BTW, I´m using Python 3 with Anaconda in a Windows 8.

Thank you for your time and support.
 

 

 

Hi Fabio,

fortunately, you won't really have to deal with command prompt stuff, just some text editing. Here's what to do:

1. Find out where you installed Anaconda. E.g., you could use the Windows search to look for "anaconda.exe" which should be located in some directory "...\Anaconda3\Scripts\". That's the directory we need in the next steps.

2. Open up a text editor of your choice, create a new text file and simply paste in the content of the bat file you already posted above (as is - nothing else to do, yet):

@REM Adapt the directory in the PATH to your system    
@SET PATH=C:\tools\Anaconda3\Scripts;%PATH%  
@CALL activate py35_knime || ECHO Activating py35_knime failed  
@python %*

3. In line

@SET PATH=C:\tools\Anaconda3\Scripts;%PATH%

replace C:\tools\Anaconda3\Scripts with the installation directory you found out in step 1. Don't delete the ";%PATH%".

4. Save the file as "py35.bat" (the name isn't really important, just make sure that the file extension is ".bat") wherever you want.

Now you can continue with "Configuring KNIME" in the blog post.

I hope that's useful.

Marcel

Hi Fabio,

 

1. Delete Anacoda stuffs becasue KNIME is going to crash with anaconda python (.dll conflict)

2. Install python 3.x stuff using pip (when installing python, use put path option in the installation icon)

3. In KNIME, go to File -> Preference->KNIME->python

   . change default python to python 3.x

    ex: C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\python.exe

4. Then, use python Nodes after put some code.

     At this moment, you have to understand python Nodes in KNIME defines input and output because KNIME is

     desinged as a workflow.

 

Good Luck!

Hi thinkchem,

could you elaborate a bit on KNIME crashing with Anaconda Python, please? (E.g. do you remember the name of the conflicting DLLs or any error messages?) That would be very helpful as it seems to be a problem we aren't aware of, so far. Thanks!

Marcel

Hi Marcel,

 

I had Anaconda python in my two computers before and installed KNIME on the two computers.

Most of KNIME nodes worked well in the both computers, but whenever starting with DL4J node,

KNIME just closed all of sudden without any error message. This occurred on the both computers at the same fashion.

 

I tried many ways to solve this problem and supposed there might be a DLL conflict between DL4J and anaconda.(guess)

Then, after deleted Anaconda and installed Python (pip), at last, DL4J worked well. On both computers!

 

I hope this can be an answer to what you asked.

 

Best,

 

 

Hi,

I want to clarify things a bit:

In the old KNIME 3.2, the DL4J version we used there had a bug that led KNIME to crash when there were conflicting mkl.dll's on the path. However, this problem was fixed beginning with KNIME 3.3 (at least nobody reported that there was still a problem, and we couldn't reproduce the problem anymore).

However, this is unrelated to the original question of this thread since this is about Keras. For the python Keras setup we recommend to use Anaconda as described by Marcel in earlier posts. There should be not problem with Anaconda and DL4J coexisting in the current version of KNIME.

Cheers

David

Hi Marcel

Very well described! Thank you!

But I still having problems.

Bellow is my batfile and attached my Knime Preferences

@REM Adapt the directory in the PATH to your system   

@SET PATH=C:\Users\Fabio\Anaconda3\Scripts;%PATH% 

@CALL activate py35_knime || ECHO Activating py35_knime failed 

@python %*

 

I tested a simple workflow using Iris.csv and Knime Plot to show a ScatterPlot but I've got the error bellow:

Execute failed: No output image found

I also tested a Knime workflow using Knime examples called PythonScripting and also failed.

Can you seed what is the problem:

Thank you for all your help.

ps. Maybe you can send me a simple workflow that works for you

 

 

Hi Fabio,

I'm glad I could help.

Your batch file and KNIME preferences look alright. Here's a very simple workflow you can use to test your Python installation. It just computes the mean value of each table row via Python.

Marcel

Hi Marcel!

Your workflow worked pretty well! Thanks for all your help! Let´s see what I can do now!

Ps: I´ve got an error using Python Plot node from Community Nodes. It is necessary to run Python Server as showed bellow but I´m not sure if this instructions are up to date.

https://github.com/knime-mpicbg/knime-scripting/wiki/Python-server-for-knime

Thank you again

Hi Fabio,

Alternatively, you could also use the "Python View" node (which is part of our regular Python integration) to plot figures. It might involve some more scripting, though.

Marcel

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