Problems creating Python Scope

Hi forum

For the first time I am testing out the Python functionality in UiPath - StudioX.

I am running a very basic program, adding 2 numbers but I am not even getting that far as StudioX is not accepting my inputs (two integers). The error is "‘Integer()’ cannot be converted to IEnumberable(Of Object)…

I suspect this is an easy fix, but I don’t seem to be able to find the solution. Workflow and error message attached.

Thanks in advance everyone!

Main.xaml (10.7 KB)
project.json (1.7 KB)

you’re trying to input an integer value into an activity that expects an IEnumerable(Of Object)
To fix this error, you can use the Python list() function to create a list containing the two integer values that you want to add

Cheers @Mark007

Hi @Palaniyappan - thanks for responding. Could you walk me through what you mean?

Do you mean create the list in the Python Script I am running?

Thanks

Mark

Can u share a screenshot of what u r doing in python script
@Mark007

Hi @Palaniyappan - I’m just testing it out before I write something substantial and so my code is just:

def add(num1,num2):
return num1 + num2

Therefore I just want to pass two integers via input parameters which is what I understood input parameters to be for.

Thanks

And actually on simplifying this further I can’t get the Python Scope working at all. I am using Python 3.11 which was installed using Anaconda.

The scope looks like in the attached, and I then used the Run Python Script activity to directly insert some simple code:

“num1 = 2
num2 = 5
def add(num1,num2):
Return num1 + num2”

Nothing was returned and StudioX just continued to run which suggests to me it’s an issue with the scope setting given it didn’t time out after 5 seconds as expected.

Any help would be really appreciated. Is it because I am using StudioX?

Thanks, Mark

@Mark007

  1. The path should be the folder where the python.exe file is present
  2. In libraries you have to give the folder where anaconda libraries are present and not the anaconda root folder
  3. Please check your .net runtime version …for python to run properly on the latest version it needs atleast 5.0.17 minutes or higher runtime to be installed

Cheers

Hi @Anil_G

I’ve changed the library directory to \anaconda3\Lib\site-packages and tried again. It still doesn’t run. I have also put a log message in front of the run command and it doesn’t run the log and so clearly I have an issue with the scope.

OK, I will upgrade my .net. I am running 4.8 (see screenshot). What version of python would I need to downgrade to in order to get it working with my current .net version as that might be easier than the upgrade as I risk impacting other software by upgrading?

There seems to be so little documentation on this and so thank you for your help!

Mark

@Mark007

https://docs.uipath.com/activities/other/latest/developer/python-scope

cheers

I have read that documentation so many times @Anil_G, how did I miss that?

Great, it’s working! Thanks, Mark

1 Like

Thanks to your help @Anil_G I have a python program now running :slight_smile:

Oddly, I can’t pass integers to the code through invoke though, I have to pass two strings and convert them in the Python code to integers. Is that expected behaviour?

Thanks
Mark

@Mark007

Can you show what error you are getting?

As far as I worked we did pass numbers

The main example itself is in numbers Mathfunction

cheers

Here’s the error I receive from StudioX before compiling:

error

If I change num1 and num2 to strings the error is no longer there and the code compiles fine, and runs the python code as expected.

Thanks

Mark

@Mark007

Ideally both to be separated with comma…you used a dot

Even with comma if you are seeing error try this

New Object(){num1,num2}

Cheers

2 Likes

I was using a comma, I think it’s just the screenshot making it look like a full stop.

Awesome! The addition of the object() works. Why is that necessary for a int but not a string?

1 Like

@Mark007

.net 5 is little stingent on the datatypes…as it needs ienum of object integers are not auto concerted to object…strings are…so previously we dint have issue…but with .net 5 declaring as object is needed

Happy Automation

Cheers

1 Like

And to you @Anil_G ! Thanks again

Mark

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