Invoke Python Method is not working for few python library

Invoke python method is not working. in my python script i have below mentioned library

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity

for this library i am getting error

error message:
Source: Invoke Python Method

Message: Pipe is broken.

Exception Type: System.IO.IOException

System.IO.IOException: Pipe is broken. at System.IO.Pipes.PipeStream.CheckWriteOperations()
at System.IO.Pipes.PipeStream.Flush()
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.set_AutoFlush(Boolean value)
at UiPath.Python.Service.PythonProxy.RequestAsync(PythonRequest request, CancellationToken ct)
at UiPath.Python.Service.PythonProxy.Shutdown()
at UiPath.Python.Impl.OutOfProcessEngine.Release()
at UiPath.Python.Activities.PythonScope.Cleanup()
at UiPath.Python.Activities.PythonScope.OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

Hi BNK,

  1. Change the Python Version
  2. Change the UiPath.python.activities version.
    image
    Cheers!

I am using UiPath.python.version = 1.7.1 and
Python version = 3.9

If i run same python script i am getting proper output (in Shell) but In Invoke method it is not wotking.

Hi @BNK ,

Please check this thread. It possibly help you!
Link: Python : Pipe is broken

Cheers!

I added the system variable for both python and pip also. still i am getting error

My python script:
import pandas as pd
import spacy
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import sys

def run_123(text):
return " Hi " + text

if name == “main”:
run(sys.argv[1])

Error:
image

I am able to run simple programs in Invoke Python method. In above program i am getting error in import statements. I tested this same code locally it is working fine but it is not working in invoke python code.

@BNK

check the reference

Hi @BNK ,

Could you please share me your .py file and also tell me how to run that file manually on system

Regards,
Vinit Mhatre

sample.zip (292 Bytes)

It is working in Shell but it is not working in invoke python code.

I think i am facing issue with below library
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity

Hi Yochi ,@Palaniyappan and @loginerror pls help on this

Hi @BNK
Here is my suggestion, if the Python invoke method does not work.

Open the cmd prompt and change the directory path to the python folder “cd /d C:\Program Files\Python310” and enter python.py script path and also you can add arguments at the end of the line, test it, and if works Use UiPath activities for cmd prompt automation in that you can able to send the change directory path, python.py path, and any argument values.

Try this and let me know

As you mentioned.I changed the path but it is not working.

If you don’t mind a workaround, you can use Invoke Power Shell to run your Python script.

image

PythonInvokeWithPowershell.xaml (7.8 KB)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.