I am using Python nodes in KNIME to write output directly to an excel file using Python package xlwings. This all worked absolutely fine until I updated to KNIME 5.2 and now I get several errors. When I configure the Python node I get the following error in the console
Starting the language server failed: Cannot run program “C:\Users\Paul.Twine.eclipse\903338280_win32_win32_x86_64\bundling\envs\org_knime_pythonscripting\python.exe”: CreateProcess error=2, The system cannot find the file specified
This appears to be pointing to the path for the bundled Python configuration even though I have chosen to point to my Conda Python distribution. The first error raised was
Execution failed: An exception was raised by the Python Proxy. Return Message: Traceback (most recent call last):
File “C:\Users\Paul.Twine.eclipse\903338280_win32_win32_x86_64\plugins\org.knime.python3.scripting.nodes_5.2.0.v202311281042\src\main\python_knime_scripting_launcher.py”, line 279, in object_to_string
string = str(obj)
^^^^^^^^
and the Python code for the Node is
import knime.scripting.io as knio
import numpy as np
import xlwings as xlw
strFilePath = “C:\Users\Paul.Twine\Downloads\”
strFileName = “20231116_RfA_Haemophilia_Society_UKHCDO_Stats.xlsx”
strFile = r’C:\Users\Paul.Twine\Downloads\20231116_RfA_Haemophilia_Society_UKHCDO_Stats.xlsx’
arrKnimeOut = knio.input_tables[0]
knio.output_tables[0] = arrKnimeOut
arrPanda = arrKnimeOut.to_pandas()
arrOut = arrPanda.to_numpy()
arrOut = arrOut[np.argsort(arrOut[:,0])]
arrGenderValues = np.array([‘F’,‘M’,‘N’,‘U’])
intTable2Row = 14
arrCountsAndMedian = np.zeros([4,2])
print(knio.flow_variables[‘strExcelFilePath’] + knio.flow_variables[‘strExcelFilename’])
with xlw.App(visible=False) as app:
wb = xlw.Book(knio.flow_variables[‘strExcelFilePath’] + knio.flow_variables[‘strExcelFilename’])
wb = xlw.Book(strFile)
for i in range(len(arrOut)):
intCount = 0
fltMedian = 0.0
intRow = np.where(arrGenderValues == str(arrOut[i,0]))[0]
if len(intRow) > 0:
arrCountsAndMedian[intRow,0] = arrOut[i,1]
arrCountsAndMedian[intRow,1] = arrOut[i,2]
wb.sheets[0].range(“B” + str(intTable2Row)).options(transpose=True).value = arrCountsAndMedian[:,0]
wb.sheets[0][“B”+ str(intTable2Row+len(arrGenderValues))].value = np.sum(arrOut[:,1])
wb.save()
Thanks,
Paul