Python activity error


#1

Main has thrown an exception

Source: Python Scope

Message: The specified Python path is not valid: C:\Python 3.7\Scripts\dist\imgprcs\imgprcs.exe

Exception Type: DirectoryNotFoundException

System.IO.DirectoryNotFoundException: The specified Python path is not valid: C:\Python 3.7\Scripts\dist\imgprcs\imgprcs.exe
at UiPath.Shared.Activities.AsyncTaskNativeImplementation.BookmarkResumptionCallback(NativeActivityContext context, Object value)
at UiPath.Shared.Activities.AsyncTaskNativeActivity.BookmarkResumptionCallback(NativeActivityContext context, Bookmark bookmark, Object value)
at System.Activities.Runtime.BookmarkCallbackWrapper.Invoke(NativeActivityContext context, Bookmark bookmark, Object value)
at System.Activities.Runtime.BookmarkWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
i have checked everything even path also .i copied the path and checked it is correct .dont know y it still throwing error


#2

Hai @AJISHA_P,

change the path directory to python.exe “C:\Python 3.7\python.exe”

Regards,
D.Aravind


#3

But my exe file is imgprcs.exe.
How can i give path python.exe


#4

You have to create a folder called Python36 in the ‘‘C’’ drive(C:\Python36) and you have to install your python in that folder.Python should be 32 bit.


#5

i created one folder python37 in C drive. And installed my python in that folder . and the python is 32 bit only.

Still the problem comes. and it is showing the same error
Python Scope : The specified Python path is not valid: C:\Python 3.7\Scripts\imgprcs.exe


#6

UiPath will support only for the python version of 3.6 and below of it.I have attached a workflow go through it and let me know if you face any issue.


#7

Python_Workflow.zip (617.8 KB)


#8

{
“message”: “Load Python Script : One or more errors occurred.”,
“level”: “Error”,
“logType”: “Default”,
“timeStamp”: “13:03:34”,
“processVersion”: “1.0.6767.29355”,
“fileName”: “Main”,
“jobId”: “eb8d7d4e-7b14-4c24-90bd-5cc79e3f04c3”,
“robotName”: “AJISH”
}

This error is coming


#9

Can you attach your workflow.


#10

Main (13).xaml (4.9 KB)

Kindly find my attachment.
(I’m Ajisha_P)


#11

i attached the file. Can you please check it


#12

Can you attach imgprcs.py file also


#13

import cv2
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import itemfreq

#flags = [i for i in dir(cv2) if i.startswith(‘COLOR_r’)]
#print(flags)

def itemfreq(a):
items, inv = np.unique(a, return_inverse=True)
freq = np.bincount(inv)
return np.array([items, freq]).T

#def rgb_2_hex(rgb):

return ‘#%02x%02x%02x’ % rgb

img = cv2.imread(‘img2.png’)
average_color = [img[:, :, i].mean() for i in range(img.shape[-1])]
arr = np.float32(img)
pixels = arr.reshape((-1, 3))

n_colors = 5
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
flags = cv2.KMEANS_RANDOM_CENTERS
_, labels, centroids = cv2.kmeans(pixels, n_colors, None, criteria, 10, flags)

palette = np.uint8(centroids)
quantized = palette[labels.flatten()]
quantized = quantized.reshape(img.shape)
dominant_color = palette[np.argmax(itemfreq(labels)[:, -1])]

#print(b’#’+b16encode(bytes(dominant_color)))
#rgb2hex(dominant_color)
print("Average Color : ", average_color)
print(“Dominant Color :”, dominant_color)

#rgb_2_hex((dominant_color))

#print(rgb_2_hex(hex()))
hex = (dominant_color[0] << 16) + (dominant_color[1] << 8) + (dominant_color[2])
print(hex)


#14

image you can give anything
i cant upload the file. because i m new user.
This is the code


#15

Hi, I am also trying to get a python script running… And I put the following into my code, but also getting an exception… (Before this, I tried the Path: “C:\Python27\python.exe” and I still have gotten the exception)…

Thanks!


#16

Please follow the bellow steps.

  1. Use Python Scope Activity and select the version of the Python and mention the installation path of the Python.
  2. Use Load Python Script activity and mention the path of the script(.py).then create a variable with the data type called PythonObject and assign that variable to Result property of this activity.
  3. Use Invoke Python Method activity and mention the Method in the property called Name, what you have defined in your Python code.Then you have to pass the Python Object in the property called “Instance”(as output created in the step 2.).Create a variable which of type PythonObject and assign that variable to property called “Output”.
  4. Use Get Python Object activity,then you have to pass the Python Object in the property called “Python Object”(as output created in the step 3.)
    5.Create a variable to store the value which is return from your Python and assign that variable to the property called “Output”.Then print the result using write line.

#17

Thank you for your detailed explanation… I have already done everything as you described (and also looked at your code that you posted above) -> still getting the same exception : “Error initializing python engine”. I think I need to install 32bit Python (as I have already seen that many are saying it doesn’t work with the 64bit)…

The other thing I wanted to ask is: In case I have more functions in my python script - > then your way won’t work? Correct me if I am wrong… Since here I was able to use just one method but in my script I have around 6 - > that means it is better to use Run Python Script Activity within Python Scope?

Thank you very much!!!


#18

An error has occured

Source: Newtonsoft.Json

Message: Error resolving type specified in JSON ‘Python.Runtime.PythonException, Python.Runtime’. Path ‘$type’, line 1, position 462.

Exception Type: JsonSerializationException

Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON ‘Python.Runtime.PythonException, Python.Runtime’. Path ‘$type’, line 1, position 462. —> Newtonsoft.Json.JsonSerializationException: Could not load assembly ‘Python.Runtime’.
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.GetTypeFromTypeNameKey(TypeNameKey typeNameKey)
at Newtonsoft.Json.Utilities.ThreadSafeStore2.AddValue(TKey key) at Newtonsoft.Json.Utilities.ThreadSafeStore2.Get(TKey key)
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.BindToType(String assemblyName, String typeName)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolveTypeName(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, String qualifiedTypeName)
— End of inner exception stack trace —
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolveTypeName(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, String qualifiedTypeName)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadMetadataProperties(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue, Object& newValue, String& id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializableItem(JToken token, Type type, JsonISerializableContract contract, JsonProperty member)
at Newtonsoft.Json.Serialization.JsonFormatterConverter.Convert(Object value, Type type)
at System.Runtime.Serialization.SerializationInfo.GetValue(String name, Type type)
at System.Exception…ctor(SerializationInfo info, StreamingContext context)
at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object[] )
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializableItem(JToken token, Type type, JsonISerializableContract contract, JsonProperty member)
at Newtonsoft.Json.Serialization.JsonFormatterConverter.Convert(Object value, Type type)
at System.Runtime.Serialization.SerializationInfo.GetValue(String name, Type type)
at System.Exception…ctor(SerializationInfo info, StreamingContext context)
at System.AggregateException…ctor(SerializationInfo info, StreamingContext context)
at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object[] )
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at UiPath.Shared.JsonParser.DeserializeObject[T](String jsonValue)
at UiPath.Models.UiPathDuplexProxy.<>c__DisplayClass18_0.b__0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()


#19

i m getting Json Serialization Exception now.
Can you Check it out


#20

I have the same problem.

Error resolving type specified in JSON ‘Python.Runtime.PythonException, Python.Runtime’. Path ‘$type’, line 1, position 462.

Please advise if the problem resolves.