Issue with loading multiple python script in UiPath

Hello All,

I have python project with more than one script, So I’m importing the sub-scripts and using it in the main script. When I run the python project from uipath it’s throwing an error.

My question is How can I load the multiple python scripts in UiPath? Or How to import the required script in the main script file?

I attached the python script for your reference.
In Python_Dic.py I initialize dictionary value, I am calling updateValue.py from Python_Dic.py and update the JSON value in updateValue.py and returning to Python_Dic.py.
When I run this from uipath it’s showing the below error.
Note: When I ran this script from command prompt it was working fine
Python Script.zip (572 Bytes)

18.4.5+Branch.support/v2018.4.Sha.2a53a262e2c1098055c3ecbdabe73d45e0a6dc29

Source: Load Python Script

Message: Error loading Python script

Exception Type: System.InvalidOperationException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: Error loading Python script ----> System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: ModuleNotFoundError : No module named ‘idc’

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object ins, Object outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at UiPath.Python.Service.IPythonService.LoadScript(String code)
at UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass11_0.b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at UiPath.Python.Activities.LoadScript.d__12.MoveNext()
— End of inner ExceptionDetail stack trace —
at UiPath.Python.Activities.LoadScript.d__12.MoveNext()
— End of stack trace from previous location where exception was thrown —
at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

Looking for reply

Regards
JothyPrasanth M

The error is not about the multiple scripts, it is not recognizing the module @jothyprasanth.m

Can you please check if it working fine when you run the code manually? And

one more thing is, you can load any number of scripts using load pythn scripts and store the loaded scripts in different variables. After that you can use the required code at required positions of the workflow

Hi @HareeshMR

It was working fine when I run it manually
If I load more then one script which instance I need to Invoke Method (Python Activity)?

Thanks
JothyPrasanth M

I mean, if you load all scripts into different variables , say py1, py2 and py3, then if you have three different methods in three scripts, whatever function you want to pass the parameters, provide that script variable in load python method @jothyprasanth.m

HI @HareeshMR
Let’s have some example

Python.Dic.py
from updateValue import updateFunc
json_str= ‘{“name”:“jothyprasanth”,“company”:“xxxx”}’
print(json_str)
def foo(dictArg):
outJson = updateFunc(dictArg) #Calling function
print(outJson)
return outJson

updateValue.py
import json
def updateFunc(dictArg):
jsonTodict = json.loads(dictArg)
jsonTodict[‘name’] = “JOTHYPRASANTH”
jsonTodict[‘company’] = “yyyyy”
outJson = json.dumps(jsonTodict)
print(outJson)
return outJson

In this example, the want to invoke function foo is under Python_Dic.py script, so I am loading the python_Dic.py script in uipath and using that instance in invoking method. The problem is inside the foo function I am invoking another function called updateFunc that is not identified in uipath and it’s throwing an error. The updateFunc is in different script.

Error from UiPath:
18.4.5+Branch.support/v2018.4.Sha.2a53a262e2c1098055c3ecbdabe73d45e0a6dc29

Source: Load Python Script

Message: Error loading Python script

Exception Type: System.InvalidOperationException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: Error loading Python script ----> System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: ModuleNotFoundError : No module named ‘updateValue’

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object ins, Object outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at UiPath.Python.Service.IPythonService.LoadScript(String code)
at UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass11_0.b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at UiPath.Python.Activities.LoadScript.d__12.MoveNext()
— End of inner ExceptionDetail stack trace —
at UiPath.Python.Activities.LoadScript.d__12.MoveNext()
— End of stack trace from previous location where exception was thrown —
at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

Hope now it’s clear.

Cheers,
JothyPrasanth M

Heyy @jothyprasanth.m,

I got it now, you are using inheritance concept here, I don’t think it is possible in uipath, why don’t you place both the functions in a same file and call within it

Hi @HareeshMR

This is just for an example, What if I have large python project that need to run from UiPath can’t keep all the function in the same file.
That’s why I want know

Anyway thanks for your response

Cheers,
JothyPrasanth M

Yeah I understand that, As we have option to load a jar file in such scenarios, you can go with that. but if you are particular with python, I don’t find any option.

I had the same problem and what I did to overcome this issue was just simply calling my main.py script from the CMD by using a Start process activity and then a Type activity.

Another solution I came up was creating a few lines of VB.NET into an invoke code activity from where I opened the CMD and called the script of python.

Hope you find this useful!

1 Like