Python Script import error

Hi,

I’m trying to integrate in KNIME a working Python program in a Python Script (legacy) Node, but some import statements seem don’t work:

import requests
from bs4 import BeautifulSoup
import pandas as pd
import os

No module named ‘requests’
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘requests’

No module named ‘bs4’
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘bs4’

Not being a Python expert, I’m asking if you have any suggestions.

Many thanks,
Alfredo

Hmm. The packages you are importing are part of the bundled environment:

# Required              # Current version in the bundled environment (December 2023)
- beautifulsoup4        # 4.12.2
- cloudpickle           # 3.0.0
- ipython               # 8.18.1
- matplotlib-base       # 3.8.2
- markdown              # 3.5.1
- nbformat              # 5.9.2
- nltk                  # 3.8.1
- nomkl                 # 1.0
- numpy                 # 1.26.2
- openpyxl              # 3.1.2
- pandas                # 2.0.3
- pillow                # 10.1.0
- plotly                # 5.18.0
- py4j                  # 0.10.9.7
- pyarrow               # 14.0.1
- python                # 3.11
- python-dateutil       # 2.8
- pytz                  # 2023.3.0
- pyyaml                # 6.0.1
- requests              # 2.31.0
- scikit-learn          # 1.3.2
- scipy                 # 1.11.4
- seaborn               # 0.13.0
- statsmodels           # 0.14.0

See here:
https://docs.knime.com/latest/python_installation_guide/#_configure_the_ap_wide_environment

Have you configured Python correctly? Preferences => KNIME => Python (Legacy)

Can you maybe switch to the “normal” Python Scropt node (non-legacy)?

2 Likes

Hi @MartinDDDD,
Thanks, the documentation was very helpful.
Solved it using the Anaconda Powershell prompt:

conda install --name py36_knime request
conda install --name py36_knime bs4
conda install --name py36_knime py4j

Regards,
Alfredo

2 Likes

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