I have a python code that works correctly but same code in the python snippet gets this error inside of the node(but not in the execution):
patool error: error extracting C:\Users\sajjad\Documents\knime-workspace.…\Rar Extraction\data\knimetemp-be29de03902b4eab\New folder.rar
could not find an executable program to extract format rar; candidates are (rar,unrar,7z),
p.s: for the python code I had to create a UNRAR_LIB_PATH variable in the system environment with the value of UnRAR64.dll. so, I guess that maybe knime has no access to the system environment?!
import os, zipfile, pyunpack
basis_folder = r'C:/Users/sajjad/Documents/knime-workspace/Rar Extraction/data/knimetemp-be29de03902b4eab/'
for root, dirs, files in os.walk(basis_folder):
for filename in files:
if filename.endswith(".rar") :
print('RAR:'+os.path.join(root,filename))
elif filename.endswith(".zip"):
print('ZIP:'+os.path.join(root,filename))
name = os.path.splitext(os.path.basename(filename))[0]
if filename.endswith(".rar") or filename.endswith(".zip"):
try:
arch = pyunpack.Archive(os.path.join(root,filename))
# os.mkdir(name)
arch.extractall(directory=root)
os.remove(os.path.join(root,filename))
except Exception as e:
print("ERROR: BAD ARCHIVE "+os.path.join(root,filename))
print(e)
try:
# os.path.join(root,filename)os.remove(filename)
pass
except OSError as e: # this would be "except OSError, e:" before Python 2.6
if e.errno != errno.ENOENT: # errno.ENOENT = no such file or directory
raise # re-raise exception if a different error occurred
I found the solution to this problem, for further issues that may come to anyone, here is the answer:
you should copy and paste the “UnRAR” file (which can be found in this path C:\Program Files (x86)\WinRAR) into the workflow folder in knime-workspace, in this scenario your python snippet can find the executable RAR file.