After a long hiatus I’ve been able to start to work with UiPath a little once again. I was very pleased to find Python activities available, but I ran into a snag here and there. I’m sharing a simple workflow to get you started. I’ll update this mini-tut as I complete more workflows.
To start, you’ll need to make sure you have Python activities available, even if you’ve loaded them for other projects, and might expect to find them already available in your new project. In 2019.6, that wasn’t the case for me. From “Manage Packages”, make sure you have this installed:
We’re going to keep this as simple as possible. All there is is a Python Scope activity, and one Load Python Script Activity. Here’s an overview of what your sequence will look like:
The Python Scope entries are crucial. I was NOT able to work with Python 3.7 64-bit, my system default. So I installed 64-bit Python 3.6 in ‘C:\Python36’. I used the generic download from python.org. Here’s what the scope properties panel looks like for me:
That’s a variable in the Input → Path field (the only one we’ll use). The entry looks like this:
In the Expression Editor for the variable, it looks like this:
Here is the Load Python Script activity, seen as when double-clicking on it.
Now we want to load that Python script as shown. For our purposes, we won’t add a path. I’m assuming the EVERYTHING is in the project directory - .xaml, python script, and output text file. Take a look at the properties:
And here it is in the Expression Editor (remember, no path needed for this simple exercise):
Okay, we’re ready to run the Python. Here’s the contents of the script:
f = open("C:\\Users\\YourUserName\\Documents\\UiPath\\InvokePython\\helloworld.txt", "w") f.write("Hello World from UiPath running Python. This time the script is loaded, not code.") f.close()
As you can see, you WILL have to change the path here, IN the file ‘Test.py’, to let UiPath know where to put the output text file.
WARNING: If you don’t add this absolute path, UiPath will drop ‘helloworld.txt’ in the folder where the NuGet package is, and you in all probability don’t want that. There are a number of posts about this elsewhere on the forum, but first things first.
About the attached files: I’m including ‘Py5.xaml’, and ‘Test2.py’. Be sure to rename the Python file to ‘Test.py’ once you’ve edited it to add the path as above, or else change the fields in the script. Your choice.
By all means let me know if this doesn’t work for you. I’ll be adding at least one more version (using code in the ‘Load Python Code’ activity instead of loading a script to run.
Once again - change that file path!
SimplePython.zip (2.0 KB)