import python packages


I have been working with Robot Framework for a short time.
In Python, I installed two additional packages: pyvisa and pyserial.
These are located in the directory: C:\Program Files (x86)\Python39-32\Scripts.
This directory is assigned to the environment variable (system variable) “Path”.
Now I want to use (import) these two packages in Robot Framework.
I have created a Robotor: Basic Python Template.
At the beginning of the file I import all the python-packages I need such as

import os
import sys
import serial
import pyvisa

When I run my Robot, the message "No module named serial" or "No module named pyvisa" appears.

My question is how to solve this problem?

Thanks a lot

Run what kind of file? A .robot?
Or are you only using Python?

Do you have a small example on how you use the library you created?

1 Like

Hello helio,

Thank you for your answer. In my example I am using a pure Python robot (Basic Python Template) - not an A.robot.
In the test case I am trying to connect to an external device using a Modbus communication over a COM port.
In my planned test case several Python scripts have to be imported. But that’s not really the problem. Because it’s about importing installed Python packages.

I show a very simple, modified Python script in which I include the Python packages. You can already see from the Python code that
the Robot Framework does not recognize the two Python packages “serial” and “pyvisa” - see line 6 and 7.

After running the python robot, the following message appears in the terminal:

But with the command “pip freeze” I can show that the two packages are installed.


Sometimes, we have more than one Python installation and we are not running the expected one.

You can try to install those modules again, but be sure to use the exact Python:

python -m pip install -U --force serial pyvisa
1 Like

Hello Helio,

thank you for your answer. I have a question. Could it be that the problem lies both with using the Python interpreter and with accessing the environment variables.
When I write a Python script and run it in VSCode (not in Robot framework),
the Python interpreter assigned to the “Path” system variable is used: C:\Program Files (x86)\Python39-32.
On the other hand, if I start a Python script in Robot-Framework, then Robot-Framework uses a Python interpreter from the directory: C:\ProgramData\robocorp\ht.

The same is with the environment variables. A normal Python script, which is not executed in the Robot Framework, accesses the directory
C:\Program Files (x86)\Python39-32\Scripts, which is also mapped to the “Path” environment variable.
The situation is different in the Robot Framework. Here folders are accessed which are located in the directory C:\ProgramData\robocorp\ht\ for example

Here my question: Is it possible to change the Python interpreter as well as the access to the environment variables in Robot Framework?
I would like Robot Framework to use the interpreter from C:\Program Files (x86)\Python39-32\ and the environment variable Path with
C:\Program Files (x86)\Python39-32\Scripts.


Maybe someone can help you with VSCode configuration.
I only use RIDE or robot from command line.

You can create a .cmd file that sets the PATH and then call VSCode, or to run robot.

1 Like