Installing external Python libraries
Installing external Python libraries
Roberty includes a Python of its own (version 3.7), which the Python code action uses. To use libraries that are not installed by default (pandas, openpyxl, requests or anything else), you install them into Roberty's Python with pip.
How it works
Roberty does not use the system's Python — it has its own interpreter, at:
C:\Users\{User}\AppData\Roaming\roberty-v4\vendor\python\3.8.1\python.exe
For a library to be available in the Python code action, it has to be installed into that particular Python, not the system's.
Step 1 — Open a Command Prompt
Press Win + R, type cmd and press Enter.
Step 2 — Enable site-packages (first time only)
Roberty's bundled Python is Windows' embedded distribution, which disables the packages directory by default. Before installing anything, enable site-packages by editing a config file.
- Open File Explorer and go to:
%APPDATA%\roberty-v4\vendor\python\3.8.1\
- Find
python37._pthand open it in Notepad. - Find the line
#import siteand remove the#, leavingimport site. - Save the file.
Step 3 — Install pip (first time only)
With site-packages enabled, download and run pip's installation script:
- Download
get-pip.pyfrom https://bootstrap.pypa.io/pip/3.7/get-pip.py - In the Command Prompt, run:
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" path\to\get-pip.py
Once it finishes, pip is installed permanently into that Python. Steps 2 and 3 are done once — you do not repeat them for later libraries.
Step 4 — Install the library with pip
Call pip through Roberty's Python:
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip install library-name
For example:
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip install pandas
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip install openpyxl requests
Wait for pip to download and install. Afterwards the library is available to any robot on that machine that uses the Python code action.
Separate the names with spaces to install several packages in one command:
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip install pandas openpyxl requests beautifulsoup4
Step 5 — Use the library in your code
With it installed, import and use it normally in the Python code action:
import pandas as pd
import json
# Takes data from the flow as JSON
data = json.loads('${JSON.stringify(actions["readSpreadsheet"]["value"])}')
df = pd.DataFrame(data)
summary = df.groupby("category")["value"].sum().to_dict()
print(json.dumps(summary))
The installation is permanent — the packages stay available to every robot on that machine for as long as the Runner is installed.
Checking what is installed
To list every library installed in Roberty's Python:
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip list
To check one in particular:
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip show pandas
Troubleshooting
No module named pip when installing.
pip is not installed yet. Follow steps 2 and 3 of this tutorial.
No module named ensurepip when trying to use ensurepip.
Roberty's bundled Python is Windows' embedded distribution and does not include ensurepip. Use the get-pip.py method in step 3.
ModuleNotFoundError when the robot runs, even after installing.
Confirm that pip ran through Roberty's Python (the full path with %APPDATA%\roberty-v4\vendor\...), not the system's (python -m pip install). Check too that python37._pth was edited correctly (step 2).
pip returns a permission error. Run the Command Prompt as Administrator and try again.
The library is not compatible with Python 3.7. Check the version's compatibility on PyPI. Some newer libraries require Python 3.8 or later — in that case, look for an older release of the package that supports 3.7:
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip install "library-name==compatible-version"
Next
- Python code — the action's full reference
- Installing external Node.js libraries — the equivalent for the JavaScript code action