Importing library 'SerialLibrary' failed

Getting error trying to import serial library in a PyCharm Robot project

My python location is at
(venv) PS C:\Users\gordo\PycharmProjects\pythonProject1> python -c “import os, sys; print(os.path.dirname(sys.executable))”
C:\Users\gordo\PycharmProjects\pythonProject1\venv\Scripts
(venv) PS C:\Users\gordo\PycharmProjects\pythonProject1>

Error when running script
Started: C:\Users\gordo\PycharmProjects\pythonProject1\Boot.robot
[ ERROR ] Error in file ‘C:\Users\gordo\PycharmProjects\pythonProject1\Boot.robot’ on line 2:
Importing library ‘SerialLibrary’ failed: ModuleNotFoundError: No module named ‘SerialLibrary’
Traceback (most recent call last):
None
PYTHONPATH:
C:\Users\gordo\AppData\Roaming\JetBrains\PyCharmCE2023.1\plugins\robotframework-intellij\lib\robotframework_debug_adapter
C:\Users\gordo\PycharmProjects\pythonProject1
C:\Users\gordo\AppData\Roaming\JetBrains\PyCharmCE2023.1\plugins\robotframework-intellij\lib
C:\Users\gordo\AppData\Roaming\JetBrains\PyCharmCE2023.1\plugins\robotframework-intellij\lib\robotframework_ls\vendored
C:\Users\gordo\AppData\Local\Programs\Python\Python310\python310.zip
C:\Users\gordo\AppData\Local\Programs\Python\Python310\DLLs
C:\Users\gordo\AppData\Local\Programs\Python\Python310\lib
C:\Users\gordo\AppData\Local\Programs\Python\Python310
C:\Users\gordo\AppData\Local\Programs\Python\Python310\lib\site-packages

Settings>Languages & Frameworks>Robot Framework (Project)
Language Server Python is C:\Users\gordo\AppData\Local\Programs\Python\Python310\python.exe
Pythonpath is[“C:/Users/gordo/PycharmProjects/pythonProject1”]

(venv) PS C:\Users\gordo\PycharmProjects\pythonProject1> pip3 install pyserial
Requirement already satisfied: pyserial in c:\users\gordo\pycharmprojects\pythonproject1\venv\lib\site-packages (3.5)
(venv) PS C:\Users\gordo\PycharmProjects\pythonProject1>

Hi Gordon,

I realise it may seem like a silly question, but I’ll ask anyway.

Did you run this in this virtual environment?

pip3 install robotframework-seriallibrary

I’m not familiar with pycharm and how it handles virtual environments, but the error seems to indicate that this package is not installed, I know you mentioned this library was working for another script and not this one, does pycharm create a different virtual environment for each script?

Dave.

(venv) PS C:\Users\gordo\PycharmProjects\pythonProject1> pip3 install robotframework-seriallibrary
Requirement already satisfied: robotframework-seriallibrary in c:\users\gordo\pycharmprojects\pythonproject1\venv\lib\site-packages (0.4.3)
Requirement already satisfied: install_requires in c:\users\gordo\pycharmprojects\pythonproject1\venv\lib\site-packages (from robotframework-seriallibrary) (0.3.0)
(venv) PS C:\Users\gordo\PycharmProjects\pythonProject1>

PyCharm created a new virial environment with the new project.

Hi Gordon,

As I don’t use robotframework-seriallibrary myself, I’m not sure how you ended up with version 0.3.0

But from the release notes that seems to be an old release that was never an official release
It seems Version 0.3.1 came out ~6 years ago, so that could be a but with the old version of seriallibrary?

try this and see if updating to the latest version helps:

pip3 install robotframework-seriallibrary==0.4.3

Dave.

(venv) PS C:\Users\gordo\PycharmProjects\pythonProject1> pip3 install robotframework-seriallibrary==0.4.3
Requirement already satisfied: robotframework-seriallibrary==0.4.3 in c:\users\gordo\pycharmprojects\pythonproject1\venv\lib\site-packages (0.4.3)
Requirement already satisfied: install_requires in c:\users\gordo\pycharmprojects\pythonproject1\venv\lib\site-packages (from robotframework-seriallibrary==0.4.3) (0.3.0)
(venv) PS C:\Users\gordo\PycharmProjects\pythonProject1>

I installed robotframework-6.0.2, then
followed Utilize Robot Framework for Hardware-In-The-Loop (HIL) Testing - DornerWorks
and followed option 1
pip install robotframework
pip install robotframework-seriallibrary
pip install robotframework-sshlibrary

Just noting that I am seeing two different instalattions/instances of Pythons here. One in the error coming from Robot when it can’t find the SerialLibrary

C:\Users\gordo\AppData\Local\Programs\Python\Python310

and then another; the virtualenv that PyCharm is using with that project and where I see robotframework-seriallibrary is being installed above

c:\users\gordo\pycharmprojects\pythonproject1\venv

So to me I understand and agree that in the first post of this thread it would not see SerialLibrary if it was installed under the virtualenv.

1 Like

I am not an expert, when I open my project in PyCharm the terminal window is setting at “(venv) PS C:\Users\gordo\PycharmProjects\pythonProject1>”. So how to I get out of the virtual environment in the terminal window to install the libraries?

You could stay with the virtualenv that PyCharm creates for you when you open the Project. This is probably what I would do. Then you would need to change the Run Configuration to use that Python instead of the system one - ..\gordo\AppData\Local\Programs\Python\Python310. Once that is done I would suspect this should start working for you.

Just changed the failure message
Started: C:\Users\gordo\PycharmProjects\pythonProject1\Boot.robot
[ ERROR ] Error in file ‘C:\Users\gordo\PycharmProjects\pythonProject1\Boot.robot’ on line 2: Importing library ‘SerialLibrary’ failed: ModuleNotFoundError: No module named ‘serial’
Traceback (most recent call last):
File “C:\Users\gordo\AppData\Local\Programs\Python\Python310\lib\site-packages\SerialLibrary_init_.py”, line 9, in
from serial import Serial, SerialBase, serial_for_url
PYTHONPATH:
C:\Users\gordo\AppData\Roaming\JetBrains\PyCharmCE2023.1\plugins\robotframework-intellij\lib\robotframework_debug_adapter
C:\Users\gordo\PycharmProjects\pythonProject1
C:\Users\gordo\AppData\Roaming\JetBrains\PyCharmCE2023.1\plugins\robotframework-intellij\lib
C:\Users\gordo\AppData\Roaming\JetBrains\PyCharmCE2023.1\plugins\robotframework-intellij\lib\robotframework_ls\vendored
C:\Users\gordo\AppData\Local\Programs\Python\Python310\python310.zip
C:\Users\gordo\AppData\Local\Programs\Python\Python310\DLLs
C:\Users\gordo\AppData\Local\Programs\Python\Python310\lib
C:\Users\gordo\AppData\Local\Programs\Python\Python310
C:\Users\gordo\AppData\Local\Programs\Python\Python310\lib\site-packages

I don’t want to debug issues with PyCharm and its plugins so I am going to install and set up RIDE.

1 Like

Uninstalled PyCharm IDE, RIDE, Robot Framework and libraries.
Reinstalled PyCharm IDE and Robot Framework. I am not using VENV, and using the base python interrupter for the project.

Installed the serial library using the PyCharm project’s terminal window.
PS C:\Development\robot-scripts\pythonProject\IOT> pip install robotframework-seriallibrary
Collecting robotframework-seriallibrary
Using cached robotframework_seriallibrary-0.4.3-py2.py3-none-any.whl (9.7 kB)
Requirement already satisfied: install_requires in c:\users\gordo\appdata\local\programs\python\python310\lib\site-packages (from robotframework-seriallibrary) (0.3.0)
Installing collected packages: robotframework-seriallibrary
Successfully installed robotframework-seriallibrary-0.4.3

Project’s test file does not indicate an issue with the *** Settings *** Library SerialLibrary encoding=ascii statement

When I run it from the command line I get this

PS C:\Development\robot-scripts\pythonProject\IOT> robot -d results tests

Tests

[ ERROR ] Error in file ‘C:\Development\robot-scripts\pythonProject\IOT\tests\RaspberryPi3B.robot’ on line 2: Importing library ‘SerialLibrary’ failed: ModuleNotFoundError: No module named ‘serial’

Hi Gordon,

Great news, looks like you’ve made some progress, before you were getting

Now you are getting

This tells me that now robot framework is recognising SerialLibrary but when it loads SerialLibrary it can’t find the serial module.

Try this

pip install pyserial

No module named serial

Making progress

PS C:\Development\robot-scripts\pythonProject\IOT> pip install pyserial
Collecting pyserial
Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB)
Installing collected packages: pyserial
Successfully installed pyserial-3.5
PS C:\Development\robot-scripts\pythonProject\IOT>

Not sure how to resolve the new error
PS C:\Development\robot-scripts\pythonProject\IOT> robot -d results tests/RaspberryPi3B.robot
==============================================================================
RaspberryPi3B
==============================================================================
System Boots | FAIL |
Parent suite setup failed:
SerialException: could not open port ‘/dev/ttyUSB0’: FileNotFoundError(2, ‘The system cannot find the path specified.’, None, 3)
------------------------------------------------------------------------------

The example I am building from has the variable for serial as “${SERIAL_PORT} /dev/ttyUSB0”.
My test setup is on Windows 11 connecting via SSH and WiFi to a Raspberry Pi 3B if this helps.

Hi Gordon,

You are using Windows? (the C:\ in the path was the clue), that port path is a *nix (Unix/Linux) or Mac thing (Mac’s run BSD Unix underneath the pretty gui), so Windows port names don’t look like that.

Based on the name of the robot file it looks like it was written for Raspberry Pi, which typically runs a variation of Debian Linux.

Are you using a USB Serial port adaptor or a traditional com port directly on your PC? Either way you’ll need to know the com port number that you want to use and replace /dev/ttyUSB0 with something like COM3 or COM10 or whatever number your com port has.

If you’re not sure how to find the comports this might help → How to check COM ports in Windows 10?

Dave.