Not able to run a python script from UiPath Studio

I want to run a python script from UiPath Studio and save the result obtained from it in a variable. Followed various videos and the explanations on various sites but not able to do it. Please help me if anyone have any idea.

I have used the below flow:
Python Scope: Gave the Python 3.6 path saved in Environment variables and selected Python_36
Load Python Script: Select the path of the python file
Invoke Python Method: Gave the o/p of Load python in Instance and gave the method name
Get python Object: Gave the o/p of Invoke Python in Python Object and saved the result in variable

But I am getting the error in 2nd step itself: Load Python Script: Error loading Python script

1 Like

I get the same message if my code contains any errors. Could you try with a file/script only containing some really simple function and see if you get the same?

Yes its a very simple code to search for a word and print it. hardly 5-6 lines of code.

Alright, did you chose the same target (x86/x64) as you have installed? Miss match here will cause this issue as well

Yes, I am using a 32-bit version and I have selected x86 as the Target

Can you share the xaml-file and the python code?

Finance_RPA2.xaml (10.8 KB)

Please find the attached file.
Below is the python code for reference:
import sys
def total():
f = open("./Sample.txt", “r”)
searchlines = f.readlines()
for i, line in enumerate(searchlines):
if “Total” in line:
for l in searchlines[i+1:i+2]:
total = l.strip()
return total

UiPath complained that it couldn’t find the file “.\Sample.txt”, and when I gave the full path to Sample.txt it worked. I don’t know if that cause you any issue but try something like this:

f = open(r"C:\Users\user\Documents\For forum\python\Sample.txt", “r”)

1 Like

Thanks @Obsev, It did solve the issue. But not sure how does it make a difference.

Anyways, thanks a lot for helping me out.