# Invoke Python Method is not working for few python library

**URL:** <https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483>\
**Category:** Activities\
**Tags:** question, python, activities\
**Created:** [February 26, 2024, 1:21pm UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483 "2024-02-26T13:21:17Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![BNK](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/bnk/32/176658_2.png) [@BNK](https://forum.uipath.com/u/BNK)\
**Post date:** [February 26, 2024, 1:21pm UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/1 "2024-02-26T13:21:17Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![jose.ordonez1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jose.ordonez1/32/462890_2.png) [@jose.ordonez1](https://forum.uipath.com/u/jose.ordonez1)\
**Post date:** [February 26, 2024, 1:43pm UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/2 "2024-02-26T13:43:15Z")

</div>

Hi [BNK](https://forum.uipath.com/u/BNK),

1. Change the Python Version
2. Change the UiPath.python.[activities](https://docs.uipath.com/activities/docs/introduction) version.  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/6/b/7/6b7605fc0a1228301688139ba717b16f54ae3e1e.png)  
Cheers!

---

<div class="post-metadata">

**Author:** ![BNK](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/bnk/32/176658_2.png) [@BNK](https://forum.uipath.com/u/BNK)\
**Post date:** [February 26, 2024, 1:46pm UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/3 "2024-02-26T13:46:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jose.ordonez1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jose.ordonez1/32/462890_2.png) [@jose.ordonez1](https://forum.uipath.com/u/jose.ordonez1)\
**Post date:** [February 26, 2024, 1:52pm UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/4 "2024-02-26T13:52:38Z")

</div>

Hi @BNK ,

Please check this thread. It possibly help you!  
Link: [Python : Pipe is broken](https://forum.uipath.com/t/python-pipe-is-broken/416962)

Cheers!

---

<div class="post-metadata">

**Author:** ![BNK](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/bnk/32/176658_2.png) [@BNK](https://forum.uipath.com/u/BNK)\
**Post date:** [February 27, 2024, 6:27am UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/5 "2024-02-27T06:27:34Z")

</div>

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](https://global.discourse-cdn.com/uipath/original/4X/1/c/1/1c1daf7d4457acdcbe19bcdcfc0f8c3089625255.png)

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.

---

<div class="post-metadata">

**Author:** ![Krishna\_Raj](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/krishna_raj/32/377808_2.png) [@Krishna\_Raj](https://forum.uipath.com/u/Krishna_Raj)\
**Post date:** [February 27, 2024, 6:30am UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/6 "2024-02-27T06:30:37Z")

</div>

@BNK

> [@Invoke Python - pipe is broken](https://forum.uipath.com/t/invoke-python-pipe-is-broken/395140):
>
> I have searched the forum and have not seen an answer that solves this for me. I have been using invoked python methods (and some existing robots are still working with this method) for a number of years. However, after the last upgrade 2021.10.4 I am getting the error below, generated from the invoke python method activity. I have tried this on a number of different python code bases to see if it changed the outcome and the summary is: If the python code base invoked is a single function o…

check the reference

---

<div class="post-metadata">

**Author:** ![Vinit\_Mhatre](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/vinit_mhatre/32/517102_2.png) [@Vinit\_Mhatre](https://forum.uipath.com/u/Vinit_Mhatre)\
**Post date:** [February 27, 2024, 6:41am UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/7 "2024-02-27T06:41:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BNK](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/bnk/32/176658_2.png) [@BNK](https://forum.uipath.com/u/BNK)\
**Post date:** [February 27, 2024, 7:05am UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/8 "2024-02-27T07:05:59Z")

</div>

[sample.zip](https://forum.uipath.com/uploads/short-url/r3EYDQVsWRW4tVXtUhXHk4bmisA.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

---

<div class="post-metadata">

**Author:** ![BNK](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/bnk/32/176658_2.png) [@BNK](https://forum.uipath.com/u/BNK)\
**Post date:** [February 27, 2024, 9:42am UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/9 "2024-02-27T09:42:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![suhas\_r](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/suhas_r/32/463766_2.png) [@suhas\_r](https://forum.uipath.com/u/suhas_r)\
**Post date:** [February 27, 2024, 1:01pm UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/10 "2024-02-27T13:01:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BNK](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/bnk/32/176658_2.png) [@BNK](https://forum.uipath.com/u/BNK)\
**Post date:** [February 28, 2024, 8:48am UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/11 "2024-02-28T08:48:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ptrobot](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ptrobot/32/175001_2.png) [@ptrobot](https://forum.uipath.com/u/ptrobot)\
**Post date:** [February 28, 2024, 12:16pm UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/12 "2024-02-28T12:16:24Z")

</div>

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

 ![image](https://global.discourse-cdn.com/uipath/original/4X/c/3/9/c394cc06a96d16d245ff8eb8528bd88f8fbe7c5c.png)

![image](https://global.discourse-cdn.com/uipath/original/4X/3/d/b/3db5d460c4cd5fa75973ca3f5d0610077799bf5b.png)

[PythonInvokeWithPowershell.xaml](https://forum.uipath.com/uploads/short-url/oTHd4eYJqgeVwPnfDt2wfxqukB9.xaml) (7.8 KB)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [March 2, 2024, 12:16pm UTC](https://forum.uipath.com/t/invoke-python-method-is-not-working-for-few-python-library/722483/13 "2024-03-02T12:16:49Z")

</div>

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