sssi
February 21, 2022, 1:29pm
1
Hello
I try to run the Python code using python activities in the UiPATH Studio.
But, following packages must be installed in advance.
from facenet_pytorch import MTCNN
from facenet_pytorch.models.utils.detect_face import extract_face
import cv2
import os
from PIL import Image
from matplotlib import pyplot as plt
import numpy as np
import math
import torch
import tensorflow as tf
import base64
import requests
from tensorflow.keras.preprocessing import image
Iโm stuck here.
How can the packages be installed in uipath?
Thank you in advance.
Srini84
(Srinivas Kadamati)
February 21, 2022, 2:24pm
2
@sssi
If the package is already installed and configured in the machine which you are running the bot then itโs fine
Can you try running it through UiPath and check what errors you are facing
Check below link for your reference
Hope this may help you
Thanks
jeevith
(Jeevith Hegde, Ph.D.)
February 21, 2022, 2:42pm
3
Hi @sssi ,
One way of managing dependencies is to make a copy of your dependencies using pip --freeze
command if you are using pip
. You do this first in the environment where all the dependencies of your code is installed and your code runs as it should.
pip freeze - pip documentation v22.2.2
pip freeze -r requirements.txt
Later when you are running your automation, ensure that the robot PC has atleast one instance of Python installed and that the requirements.txt
file can be accessed via the robot pc. You can even save the contents of the requirements.txt
as a text asset in the Orchestrator and fetch it as and when you need from the robot.
You can use the Invoke PowerShell activity to run the following command (ensure the you have a full path to requirements.txt generated in Step 1). Another requirement is that pip
should be cmdlet which can be accessible by PowerShell.
pip install -r requirements.txt
PowerShell can now install all the modules you require.
Let your python code do the rest. (Python scopeโ>Returnsโ>UiPath(.net classes) )
Alternative:
A similar process can be used if you are using conda
. The commands will be slightly different.
When active in your source environment
conda list -e > requirements.txt
When you are in a given target conda enviornment you can use
conda install --file requirements.txt
sssi
February 22, 2022, 6:21am
4
Hello, @Srini84
I checked that the package was installed in the system and that the code runs as it should on other IDLE.
But, the following error occurred when I run it in UiPath.
The error message says, โThe pipe is broken.โ
RemoteException wrapping System.AggregateException: ํ๋ ์ด์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ---> RemoteException wrapping System.InvalidOperationException: Python ๋ฉ์๋ ํธ์ถ ์ค ์ค๋ฅ ---> RemoteException wrapping System.IO.IOException: ํ์ดํ๊ฐ ๋์ด์ก์ต๋๋ค.
์์น: System.IO.Pipes.PipeStream.CheckWriteOperations()
์์น: System.IO.Pipes.PipeStream.Flush()
์์น: System.IO.StreamWriter.Flush(Boolean flushStream,
Boolean flushEncoder)
์์น: System.IO.StreamWriter.Dispose(Boolean disposing)
์์น: System.IO.TextWriter.Dispose()
์์น: UiPath.Python.Service.PythonProxy.RequestAsync(PythonRequest request,
CancellationToken ct)
์์น: UiPath.Python.Service.PythonProxy.InvokeMethod(Guid instance,
String method,
IEnumerable`1 args)
์์น: UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass15_0.<InvokeMethod>b__0()
์์น: System.Threading.Tasks.Task`1.InnerInvoke()
์์น: System.Threading.Tasks.Task.Execute()
--- ์์ธ๊ฐ throw๋ ์ด์ ์์น์ ์คํ ์ถ์ ๋ ---
์์น: System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
์์น: System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
์์น: UiPath.Python.Activities.InvokeMethod.<ExecuteAsync>d__16.MoveNext()
--- End of inner exception stack trace ---
์์น: UiPath.Python.Activities.InvokeMethod.<ExecuteAsync>d__16.MoveNext()
--- End of inner exception stack trace ---
์์น: UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context,
IAsyncResult result)
์์น: System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context,
IAsyncResult result)
์์น: System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor,
BookmarkManager bookmarkManager)
Srini84
(Srinivas Kadamati)
February 22, 2022, 6:23am
5
sssi:
The pipe is broken
@sssi
Check below post for your reference
Hi ,
Found the issue and corrected it.
I was using read function to read a file but since the file was too long it was throwing this error
with open(filename,'r+') as pre_file:
raw_data=pre_file.read()
pre_file.close()
It was resolved when I used readlines function instead -
with open(filename,'r+') as pre_file:
raw_data=pre_file.readlines()
pre_file.close()
Thanks for your time anyways,
Regards.
Hope this may help you
Thanks
sssi
February 22, 2022, 8:31am
6
Thanks for reply, @Srini84
I checked the post you linked above but, I couldnโt find answer for my case.
This is my python code.
I pass the image path as parameter to detect_face function.
And it returns boolean value depending on whether the image has a face or not using the MTCNN library.
But, the error occurs and, the error message says, โThe pipe is broken.โ (I posted above.)
import cv2
import os
import numpy as np
from facenet_pytorch import MTCNN
def detect_face(img):
mtcnn = MTCNN()
if os.path.isfile(img) != True:
raise ValueError("Confirm that ", img, " exists")
path = np.fromfile(img, np.uint8)
img = cv2.imdecode(path, cv2.IMREAD_UNCHANGED)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
boxes, probs, landmarks = mtcnn.detect(img, landmarks=True)
if (boxes is None):
raise Exception('Cannot detect face')
return False
else:
return True
sssi
February 22, 2022, 8:38am
7
Hi, @jeevith
Thank you for your kind answer
I solved the package dependency problems, but I am stuck with this problem now.
Can you help me?
Thanks for reply, @Srini84
I checked the post you linked above but, I couldnโt find answer for my case.
This is my python code.
I pass the image path as parameter to detect_face function.
And it returns boolean value depending on whether the image has a face or not using the MTCNN library.
But, the error occurs and, the error message says, โThe pipe is broken.โ (I posted above.)
import cv2
import os
import numpy as np
from facenet_pytorch import MTCNN
def detect_face(img):
mtcnn = MTโฆ
Hi @sssi ,
If you are facing any dependency issue of the packages you can upgrade/downgrade the package from manage packages to best suit your requirements.
Thanks
jeevith
(Jeevith Hegde, Ph.D.)
February 22, 2022, 10:02am
9
Hi @sssi
How did you solve this? May be others having the same problem can use what you used. Kindly pen it down in this thread.
def detect_face(img):
You are doing everything right here. But one heads up is converting python return types to .net types can be often clumbersome.
What I learnt from expierence is that it is easier to use json string as a return from python.
For example, your code could look like:
import json
import cv2
import os
import numpy as np
from facenet_pytorch import MTCNN
def detect_face(img):
mtcnn = MTCNN()
if os.path.isfile(img) != True:
raise ValueError("Confirm that ", img, " exists")
path = np.fromfile(img, np.uint8)
img = cv2.imdecode(path, cv2.IMREAD_UNCHANGED)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
boxes, probs, landmarks = mtcnn.detect(img, landmarks=True)
if (boxes is None):
raise Exception('Cannot detect face')
result = { 'result': False}
return json.dumps(result)
else:
result = { 'result': True}
return json.dumps(result)
In UiPath you can then use the desearlize json activity (UiPath.Web.Activities) to get the value of return value result
Here is another example of using json strings and parsing it in UiPath : How to use permuation and combination in excel uipath - Help - UiPath Community Forum
Some threads for you to read about Pipe is broken error , which I have come across and some reasons for it.
1 Like
sssi
February 22, 2022, 6:31pm
10
Hi @jeevith
This was the solution.
If the package is already installed and configured in the machine which you are running the bot then itโs fine. You donโt need to install the package additionally.
You donโt need to install the package additionally in UiPATH.
Iโll try the way you suggested. Thank you so much.
system
(system)
Closed
February 25, 2022, 6:31pm
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.