Create

How to Set Up the Python Extension

March 18, 2021 — by Mahantesh Pattadkal
How to Set Up the Python Extension

With the Python integration in KNIME you can use an existing Python installation from KNIME Analytics Platform. But what if Python is not yet installed on your system? Here is a quick step by step guide on how to install Python, get it working in KNIME, and also configure the Python Deep Learning extensions. 

The KNIME Python and Deep Learning integrations are widely used. They contain Python based nodes to integrate Python versions 2 or 3 as well as Deep Learning nodes. For the purpose of this article, we’ll assume here that Python is not yet installed on your system. 

Installing extensions in KNIME has been simplified greatly over time. You just drag&drop from the KNIME Hub to your installation of KNIME. Any troubleshooting issues here around installation should be resolved!

1. Install the KNIME Python Integration 

You’ll find the Python integration on the KNIME Hub. Enter Python in the search field and filter by Extensions. With your version of KNIME Analytics Platform open, drag the Python Integration download icon over to the Workflow Editor.

How to Set Up the Python Extension
Fig. 1. Install a KNIME extension by drag&drop from the KNIME Hub to your KNIIME Analytics Platform workflow editor.

2. Install a KNIME Deep Learning Integration

If you want to use Python for deep learning, you will need to install one of the KNIME Deep Learning Integrations as well. You’ll find different deep learning integrations on the KNIME Hub, for example for Keras, TensorFlow, TensorFlow2, ONNX, etc. Choose the one(s) that you need for your project. Follow the same procedure as above to locate them on the Hub and install on your system.

3. Install Anaconda to Manage your Python Environments

Install Anaconda or Miniconda from the links below and choose the version of Python you prefer. We recommend using either the:

  • Anaconda Python distribution from Continuum Analytics - the full toolkit to work with thousands of open source packages and libraries, or
  • Miniconda - a minimal installer for conda, which includes only conda, Python, the packages they depend on, plus a small number of other useful packages.
We recommend using Python 3: this affects only your default Python environment. Note that you can create environments with other Python versions without needing a new install. For example, if you install Anaconda3 you can still create Python 2 environments.

4. Set Up your Python Environment

In your installation of KNIME Analytics Platform, go to the Preferences page under File menu. Under KNIME you'll find up to three Python-related options (based on the installed extensions): Python, Python Deep Learning, and Python Scripting. (Python Scripting is a community extension, which we won’t cover here in this article.)

The “Python” option in your preferences page is visible only if you have installed the KNIME Python Integration Extension. In case you cannot see this option in your preferences page, consider installing the KNIME Python Integration Extension as described above in step 1.

Click the Python option to open the Python preferences.

Here, select Conda under Python environment configuration as shown in Figure 2.

Next, the page will specify a default Anaconda installation folder as per default installation (here). If you have installed Anaconda to a different location, provide the path to your Anaconda installation folder.

Once a valid path has been entered, you will see the conda version number shown on this page. Now choose which conda environment you want to use for Python 3 and Python 2 from the combo box.

Fig. 2. Preference Page for Python (click image to see a larger version)

If you have already set up a Python environment, containing all the necessary dependencies for the KNIME Python Integration, just select it from the list and you are ready to go. If you do not have a suitable environment available yet, click the New environment... button. This opens the following dialog (Figure 3):

Fig. 3. Dialog to create a new environment (click image to see a larger version)

Provide a name for the new environment and click the Create new environment button. This creates a new conda environment containing all the required dependencies for the KNIME Python Integration.

Once the environment is successfully created, the dialog closes and the new environment is selected automatically. If everything worked out fine, the Python version is now shown below the environment selection and you are ready to go.

After the environment is created, you can run Jupyter notebooks as well as the Python-based nodes such as Python scripting, Python Object Reader etc. 

Example workflows that use the KNIME Python Integration 

Here are two workflows that you can download and try out yourself if you want to try out using Jupyter Notebook in combination with KNIME.

5. Set Up your Python Deep Learning Environment

In your installation of KNIME Analytics Platform, go to the Preferences page in File menu. Under KNIME, click the Python Deep Learning option.

In the Python Deep Learning preferences (Figure 3) you have two options for configuring the Python Deep Learning environment.

Fig. 4. Preference page for Python Deep Learning (click image to see a larger version)

Option 1: Use special deep learning configuration (recommended)

If you select this option, KNIME Deep Learning will use a different Python 3 environment to the one configured in the Python Preference page.

Similar to the Python preferences page, you can either automatically create Python 3 environments containing all required packages (by selecting the Conda sub option), or point to Python start scripts that activate a suitable environment you created manually (by selecting the Manual sub option).

We recommend choosing Conda. If you do so, the dialog will look like the one shown in Figure 4.

If you have already set up a Python Deep Learning environment containing all the necessary dependencies for KNIME Deep Learning, just select it from the list and you are ready to go. If you do not have a suitable environment available, click the New environment… button. This opens the following dialog (Figure 5):

Fig. 5. Dialog to create New Python environment for Deep Learning (click image to see a larger version)

Option 2: Use Python configuration

If you choose this option, KNIME Deep Learning will use the same Python 3 environment as configured in the Python preference page. This assumes that this Python 3 environment already contains all required Python Deep Learning packages (which have to be installed manually).

A list of the required Python Deep Learning packages for the Keras Integration is documented in the KNIME Keras Integration Installation section. This option is intended for advanced users, we recommend choosing Option 1.

Example workflows that use the KNIME Deep Learning Integration 

6. Install Additional Python Packages (optional)

The environment created using the Anaconda configuration only contains the packages as listed here. So, if you want to use Python packages other than the ones listed in the configuration files, these can be easily added manually after the environment has been created. 

For example, if you want to use the scikit-learn package for data processing or ML based models in KNIME Python nodes, use the following command:

conda install --name <> scikit-learn

Wrap-up: Python-Related Resources at a Glance

This article was designed as a quick guide to not just installing and setting up the KNIME Python Integration and Deep Learning Integration for Python, but to give you some links to our favorite Python-related content on the KNIME website.

Workflows on KNIME Hub

Blog Articles

Documentation

You may also like
Create

You don't have to choose! Blending KNIME and Python

This is going to be a bit different from our normal KNIME blog posts: instead of focusing on some interesting way of using KNIME or describing an example of doi...

October 23, 2017 – by Greg Landrum
Create

Deploying the Obscure Python Script: Neuro-Styling of Portrait Pictures

With the excuse of playing around with neuro-styled portraits of Rosaria and Misha and their colleagues, we show how easy it is to import, integrate and deploy an obscure Python script — without needing to know Python.

November 4, 2019 – by Rosaria Silipo &  Mykhailo Lisovyi