Skip to main content
Roberty Studio
RPATutorials

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.

  1. Open File Explorer and go to:
    %APPDATA%\roberty-v4\vendor\python\3.8.1\
  2. Find python37._pth and open it in Notepad.
  3. Find the line #import site and remove the #, leaving import site.
  4. Save the file.

Step 3 — Install pip (first time only)​

With site-packages enabled, download and run pip's installation script:

  1. Download get-pip.py from https://bootstrap.pypa.io/pip/3.7/get-pip.py
  2. In the Command Prompt, run:
bat
"%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:

bat
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip install library-name

For example:

bat
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip install pandas
bat
"%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.

Installing several at once

Separate the names with spaces to install several packages in one command:

bat
"%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:

python
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:

bat
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip list

To check one in particular:

bat
"%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:

bat
"%APPDATA%\roberty-v4\vendor\python\3.8.1\python.exe" -m pip install "library-name==compatible-version"

Next​