How to invoke python method that uses a non-builtin library (OPENPYXL)

Hello all,

We are trying to run a python code (script attached – ExcelTest.py) with UiPath (workflow attached – FuncExcelTest.xaml). We manually import some external libraries to python (eg openpyxl) and, when trying to run the python code manually works but, through UiPath it give us the error “No module named ‘openpyxl’” (attached in the picture C511092.png).

Is there any way we could invoke a python script using non-builtin libraries?

Many thanks in advance!

Find attached the XAML file FuncExcelTest.xaml (7.0 KB)
The python script :

def ExcelFunction(text):
try:
import openpyxl
print(“imported”)
except Exception as inst:
print(str(inst))
return(str(inst))
try:
wb2 = openpyxl.load_workbook(“C:/Users/XXXX/Documents/Python Scripts/hello.xlsx”)
sheet = wb2[“renamed”]
sheet[‘B2’]=“21/07/2018”
wb2.save(“hello.xlsx”)
print(“OK”)
return(text)
except Exception as inst:
print(str(inst))
return(str(inst))

The error: C5110092

1 Like

I have the same problem! Did you resolved it ?@Manel

hello,
did you get the solution for importing packages. I’m facing same kind of trouble in my program. please help me to fix it

Hi,

I am facing the same issue, did you find a solution for this?

Best regards,
Christofer

I have the same problem. Did any of you find a solution?

Hi @sasanka.desu

Could you see this post?

It might be helpful!

Just install the library openpyxl using pip on command line. There are dependencies which we don’t encounter while executing the script on python IDE

1 Like

I encountered the same problem when using “import openpyxl” or “import pyodbc” in the Python script. The script worked fine in Python, but when I tried using the Invoke Python Method in UiPath, the code failed with an error. I determined that UiPath was not seeing the files related to openpyxl or pyodbc when using the Invoke Python Method in UiPath. UiPath is not looking in the working folder for these files. It is looking in the Python scripts folder. I discovered that on a Windows computer you need to launch a command prompt and navigate to the pythons scripts folder. On my computer, it was “C:\users\username\AppData\Local\Programs\Python\Python38-32\Scripts”. But, you need to replace username in the path with your Windows user name. From this folder I ran the following command:

“python -m pip install -U pip setuptools”

This code enabled the ability to do a pip install in the Python scripts folder. Then I executed the following commands in the Python scripts folder:

“pip install openpyxl”
“pip install pyodbc”

After taking these actions, the Python script ran with no problems.

1 Like