Python library

Hello Everyone,

Hope you are all well and safe. I wrote a small script in python script (1=>1) with importing the whois library, but when I am running the script it keeps telling me ModuleNotFoundError. this is the whole error i get while I am running the script:

ERROR Python Script (1⇒1) 3:341 Execute failed: No module named ‘whois’
Traceback (most recent call last):
File “”, line 2, in
ModuleNotFoundError: No module named 'whois

Do you have any idea how can I fix this problem?

Thanks in advance
Safa

I tried to figure out how to import and use an external python module in KNIME and came up with this setting how to use external python scripts from (a) separate file(s).

There also is the option to use Jupyter notebooks. Here are the workflows from a recent session (https://youtu.be/1Rr8Q27k7cQ ) by https://hub.knime.com/mpattadkal and @paolotamag.

1 Like

Hi @mlauber71,

Thank you very much for your reply. I tried both of them but still, get the same error that no module named whois. I also tried other python nodes but the same error occurs every time. Is there another way to fix this problem?

Kind regards,

Safa

Could you provide us with a sample of the workflow and maybe the module to see what is going on. Are you able to successfully set up a minimal module?

The error message indicates that -well- the module is still not found. I had to use a few trys to set up the working small example.

Hi again @mlauber71,

Please find the workflow in the attachment. By the way, I can completely run this code on python IDLE 3.9 (64 bit) and it works perfectly.

Thanks in advance

Safa

urls.knwf (7.5 KB)

I think you have to properly install the whois package then it is accessible thru KNIME.

import whois
import pandas as pd

result = whois.query("knime.com")

data = {'Creation Date':[result.creation_date],
		'Expiration Date':[result.expiration_date],
		'Last updated':[result.last_updated],
		'Name':[result.name],
		'Name Servers':[result.name_servers],
		'Registrar':[result.registrar],
		'Status':[result.status],

} 
  
# Create DataFrame 
output_table = pd.DataFrame(data)

urls.knwf (16.6 KB)

Hi @mlauber71,

Thank you very much for your help I tried but still get the same error, I installed everything on the system, but unfortunately, the same error appears all the time and I think the problem is from my end.

Thanks again.
Regards,

Safa

1 Like

You are welcome. Interestingly who is would only show up once I installed it via PIP not via anaconda although it was listed via “conda list”.

Maybe you check your KNIME and python setup once more. In general KNIME does work with newer python versions but I think there always is a recommended one,

I did all the configuration for python on knime platform, the only thing that couldn’t configure is “Tensorflow2” which gives error all the time. I installed it on my system but I don’t know why Knime keeps giving error that is not installed on the system. Can you please check your system to see if tensorflow installed on you system, if yes so i will go and fix that one if not i will check other configuration on my system.

Kind Regards

Safa

Safest course of action is to use anaconda/miniconda and then have KNIME create the python environments. You can create one for general use and a separate environment for deeplearning (actually you can create 2 envs for deeplearning, one for keras (I presume TF1 based) and one for TF2).

To use a package then simply install the package into the appropriate environment, for the scripting node that would obviously be the “general use” environment.

Official supported python version I think is still only 3.6 but 3.7 works too. Haven’t tried 3.8 or 3.9.

1 Like

Hi,

I have a similar problem with the “phone-iso3166” module. Then I install the package in the Python Edit variable and then the import works.

image

The code in the Python Edit variable node is:

import subprocess
import sys
def install(package):
subprocess.call([sys.executable, “-m”, “pip”, “install”, “–user”, package])
install(“phone-iso3166”)
flow_variables[‘installed’] = “true”

Afther that I have no problems with importing the package.
Give it a try

Dear all,

Thank you very much for all your replies. After 4 days of working on this, I could finally manage to find out where was the problem. @mlauber71’s workflow didn’t work on my system. I checked everything and finally find out the installation of “whois” is only working on Linux and Mac OS, but not in windows OS.

If you want to run this module on Windows, you have to install “python-whois” in your working environment. Now my problem is solved but still couldn’t manage to read values directly from the table.

I have a table with a couple of URLs and already connected it to the python script (1=>1) node. please find the workflow in the attachment. Do you have any clue how can I twist python script to read my values through the table directly and check the URLs for their creation and expiration date and store all the result in a new table?

Kind Regards,

Safa

newURL.knwf (7.1 KB)

Hi,

I can not see any data. Can you please do not reset the workflow during the export process, so we will see your data or upload the csv file.

Thank you

1 Like

Hi @andrejz,

Thank you for your reply. please find the workflow in the attachment.

Regards,

Safa

newURL.knwf (12.8 KB)

Hi,

You have to loop over rows …

Hi again @andrejz,

Thank you for coming back to me so quickly. What syntax I can use to twist the python script (1:1) node start to read values from my table? I will appreciate if you could give me an example workflow for a loop as I am new in Knime and didn’t use a loop over before.

Thank you in advance.

Regards,
Safa

Hi,

You can loop with group loop node for example.

image

or you can loop inside the python code (for or use python lambda function)

I will also suggest to append the result of whois to the input table

Hi @andrejz,

Thank you very much for the workflow. I tried this and works perfectly if I write the domain name inside my code but when I want the script reads all URLs from my table it couldn’t manage to read it. I send a screenshot of my code. could you please check my code where I am wrong that the python script node does not read URLs from my table?

Thanks in advance.

Regards,
Safa

Hi,

With

domain = input_table[‘url’]

you read all the column …
You have to read the element from the table … try

domain = input_table[‘url’][0]

Hi @andrejz,

Now it looks ok. it seems to read all the rows from the URL table and create the result table, but I don’t why it give a null result. it seems for some reason it doesn’t check the whois in line 9 of my code.