How to run pyhton script in uipath

Hi all,

I have written python code in pycharm, I have to run that script using Uipath, I tried by using run python script inside python scope in UI path. Am not getting any error, I have provided necessary path but not getting output. Please If anyone gives a solution on how to run this script will be useful to learn.

Thanks In Advance.

1 Like

Hi @DivyaT,

Are you trying to return anything from the code?

Here is the sample workflow to invoke python code in UiPath. Let me know if you have doubts.

Python.zip (4.7 KB)

yes am trying to get output, i have written the script for converting scanned pdf to image and extracting the text but am not getting anything after ran the script using uipath.

New folder.zip (2.3 KB)

this is my script and Uipath activity.

@DivyaT,

Can you try running the file in the actual environment instead of running in virtual environment?

That is one of the issues I faced earlier and run the code in Load Python Script activity which will let you know where the code is failing?

Is version would be a problem? because i have downloaded python 3.7 but uipath have version upto 3.6

How to assign python object variable in load python script

Nothing you need to assign, just use the path in python scope and within that, use Load Python Activity and give the path

getting error in loading script , is version will be the problem?

May be… What is the error? Can you post the screenshot please?

@DivyaT,

The thing is that, I’m getting the same when I run the code you uploaded, open and check the details so you can found some error there regarding pytesseract.

when i run that script am getting output, but while running through uipath am not getting anything.

Yeah @DivyaT,

That is known thing with UiPath :blush: … As we have discussed, it may be a version issue as well. Python 3.7 is compatible with uipath is still a question for me? If you have any chance, try installing 3.6 version and check. Caution: Don’t use Virtual environments in UiPath

ok thank you

After install 3.6 also am getting repeated errors, can anyone please give solution am facing difficulty in this.

Hi @DivyaT

Just to clarify - is your Python exe file in this location?
C:\Users\user\AppData\Local\Programs\Python\Python37\Scripts

This path should be the path to the folder with the python exe file.

1 Like

yes this is my python execution path,Actually am using pycharm interprete with python v3.6.7

Hi Divya,

Can you share your python file?

New folder.zip (2.3 KB)

this is my script and Uipath activity.
Thank you.

Hi Divya,

I have gone through the code and script.

You cannot directly run a python script through UiPath. It isn’t a reliable approach or a stable approach to follow.

Python script:
The script has to be in form of a function.
Example : def(a,b):
return(a+b)
I have transformed your script into a function. It requires two inputs.
Inp PDF file and Op Excel file.
Pass them in the UiPath program and it’ll run.
Also, make sure you have the necessary libraries installed.

Inside Python Scope,

First Load the python script. It creates an Instance
Pass the first instance to Invoke Python Method Activity. Give the necessary Input and Output.
It will call that particular method and perform the task.
In a Py function, you return something. So, the Get python Object activity fetches the Output of the function.

Attaching the zip file, Please go through it.

PyOCR.zip (3.0 KB)

5 Likes