Python activities with matplotlib

Hi,

I am trying to start python script:

def test_function(x):
import matplotlib.pyplot as plt
plt.plot([x1,x2,x3,x4])
plt.savefig(‘test.png’)
return result_of_function

This script creates simple graph in matplotlib and save it as png file.
I am using ‘Load Python Script’ and ‘Invoke Python Method’.
I am getting error:

'An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.AggregateException: One or more errors occurred. ----> System.InvalidOperationException: Error invoking Python method ----> System.ServiceModel.CommunicationException: There was an error reading from the pipe: Unrecognized error 109 (0x6d). ----> System.IO.PipeException: There was an error reading from the pipe: Unrecognized error 109 (0x6d).
at System.ServiceModel.Channels.PipeConnection.FinishSyncRead(Boolean traceExceptionsAsErrors)
at System.ServiceModel.Channels.PipeConnection.Read(Byte buffer, Int32 offset, Int32 size, TimeSpan timeout)
— End of inner ExceptionDetail stack trace —

Server stack trace:
at System.ServiceModel.Channels.PipeConnection.Read(Byte buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.DelegatingConnection.Read(Byte buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.SessionConnectionReader.Receive(TimeSpan timeout)
at System.ServiceModel.Channels.SynchronizedMessageSource.Receive(TimeSpan timeout)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.Receive(TimeSpan timeout)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceive(TimeSpan timeout, Message& message)
at System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message message, TimeSpan timeout)
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.InvokeMethod(Guid instance, String method, IEnumerable1 args) at UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass12_0.<InvokeMethod>b__0() at System.Threading.Tasks.Task1.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.InvokeMethod.d__16.MoveNext()
— End of inner ExceptionDetail stack trace —
at UiPath.Python.Activities.InvokeMethod.d__16.MoveNext()
— End of inner ExceptionDetail stack trace —
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)’

Do anyone knows why I get this error? and how to run this script?

Hi @piomio,

If your code works fine in any IDE, then it should work in UiPath as well.

Do the following steps using Invoke Python Method:

  1. Load Python Script activity and give the path of the python code

  2. Use Invoke Python method in the code.
    Pass the parameters required
    a) Input params whatever you want to pass to the function in the python
    b) Instance is the output of Load Python Script activity
    c) Name → Name of the function in the code

  3. Save the output in a variable

  4. Use Get Python Object and you will get the result here. Change the type to required type.

I hope you are missing some steps here…

Hi,

did just that. It works fine with numpy (check zip test1.py) but I get error when I try to use matplotlib libery (check zip test2.py). Test2.py compiles normally in virtual env. Any idea what could be the source of this problem?


TestPython.zip (12.4 KB)

Can you try running the UiPath Studio as Administrator…

If you still have the same issue…

  • Make sure Net.Pipe Listener Adapter service is running:
  1. Got to run & open Services.msc
  2. Make sure Net.Pipe Listener Adapter service is running.

It looks like ‘Net.Pipe Listener Adapter’ it is not running because I don’t have it (check picture). Do you know how to install it? Or there is some other way?

Finally, Can you try running the studio as Administrator?

If it won’t work, will check someother :slight_smile:

I was running it as administrator and got this error:

image

The reasons are many as i tried to google the error,

  1. I think, the python path has to be changed in the Python scope activity while you are running in virtual environment

or

  1. Try installing all the dependencies in the regular path and run the test2.py as you are running test1.py …

That would help

I reinstall python36 and change Python Scope Path to newly installed python and it works :slight_smile: Thanks for your help.

Great… So, the error is with the virtual environment dependency on the code right?
@piomio

Yes It looks that way.

1 Like