# Importing library 'SerialLibrary' failed

**URL:** <https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725>\
**Category:** Libraries\
**Created:** [21 May 2023 19:52 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725 "2023-05-21T19:52:41Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [21 May 2023 19:52 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/1 "2023-05-21T19:52:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [21 May 2023 20:02 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/2 "2023-05-21T20:02:38Z")

</div>

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”]

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [21 May 2023 20:06 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/3 "2023-05-21T20:06:25Z")

</div>

(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\>

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [21 May 2023 20:17 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/4 "2023-05-21T20:17:41Z")

</div>

![Python Interpreter](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/c/c27ee1052fd6e6231f87c85134730d1cb0d969b6.png)

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [22 May 2023 04:22 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/5 "2023-05-22T04:22:49Z")

</div>

Hi Gordon,

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

Did you run this in this virtual environment?

```python
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.

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [22 May 2023 20:12 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/6 "2023-05-22T20:12:04Z")

</div>

(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.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [23 May 2023 00:05 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/7 "2023-05-23T00:05:56Z")

</div>

Hi Gordon,

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

> [@gordongilbert](#):
>
> Requirement already satisfied: install\_requires in c:\users\gordo\pycharmprojects\pythonproject1\venv\lib\site-packages (from robotframework-seriallibrary) (0.3.0)

But from the [release notes](https://github.com/whosaysni/robotframework-seriallibrary/blob/develop/CHANGES.rst) 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:

```python
pip3 install robotframework-seriallibrary==0.4.3

```

Dave.

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [23 May 2023 21:28 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/8 "2023-05-23T21:28:32Z")

</div>

(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](https://dornerworks.com/blog/robot-framework-tutorial/)  
and followed option 1  
pip install robotframework  
pip install robotframework-seriallibrary  
pip install robotframework-sshlibrary

---

<div class="post-metadata">

**Author:** ![EdManlove](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/edmanlove/32/1002_2.png) [@EdManlove](https://forum.robotframework.org/u/EdManlove)\
**Post date:** [23 May 2023 22:02 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/9 "2023-05-23T22:02:46Z")

</div>

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

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

```python
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.

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [24 May 2023 16:15 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/10 "2023-05-24T16:15:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [24 May 2023 16:23 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/11 "2023-05-24T16:23:54Z")

</div>

![PyCharm packages](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/1/147613b2805ae671214bbccc21ce9a1edd48262c.png)

---

<div class="post-metadata">

**Author:** ![EdManlove](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/edmanlove/32/1002_2.png) [@EdManlove](https://forum.robotframework.org/u/EdManlove)\
**Post date:** [24 May 2023 16:50 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/12 "2023-05-24T16:50:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [24 May 2023 17:11 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/13 "2023-05-24T17:11:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [24 May 2023 17:52 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/14 "2023-05-24T17:52:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [6 June 2023 22:11 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/15 "2023-06-06T22:11:56Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [6 June 2023 23:39 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/16 "2023-06-06T23:39:10Z")

</div>

Hi Gordon,

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

> [@gordongilbert](#):
>
> Importing library ‘SerialLibrary’ failed: ModuleNotFoundError: No module named ‘SerialLibrary’

Now you are getting

> [@gordongilbert](#):
>
> [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’

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
pip install pyserial

```

[No module named serial](https://stackoverflow.com/questions/33267070/no-module-named-serial)

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [7 June 2023 17:00 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/17 "2023-06-07T17:00:17Z")

</div>

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)**  
**------------------------------------------------------------------------------**

---

<div class="post-metadata">

**Author:** ![gordongilbert](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gordongilbert](https://forum.robotframework.org/u/gordongilbert)\
**Post date:** [7 June 2023 18:59 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/18 "2023-06-07T18:59:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [8 June 2023 11:35 UTC](https://forum.robotframework.org/t/importing-library-seriallibrary-failed/5725/19 "2023-06-08T11:35:21Z")

</div>

Hi Gordon,

> [@gordongilbert](#):
>
> ould not open port ‘/dev/ttyUSB0’

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?](https://superuser.com/questions/1059447/how-to-check-com-ports-in-windows-10)

Dave.
