Pyserial: "module 'serial' has no attribute 'tools'"
Asked Answered
S

2

7

I have some Devices connected to my Notebook via a RS485 to USB Converter and want to detect them in a python programm.

I'm running this Code with PyCharm Community Edition on a Windows 7 Notebook, I've installed pyserial with pip.

import serial

x = list(serial.tools.list_ports.comports())
print(x)

And got this error:

Traceback (most recent call last): File "C:/Users/rzzrgx/.PyCharmCE2018.3/config/scratches/scratch_1.py", line 3, in x = list(serial.tools.list_ports.comports()) AttributeError: module 'serial' has no attribute 'tools'

Scandinavian answered 21/1, 2019 at 10:57 Comment(0)
E
17

Wrong way to import , correct it like below:


from serial.tools import list_ports

x = list(list_ports.comports())
print(x)

or


import serial.tools.list_ports

plist = list(serial.tools.list_ports.comports())
print(plist)

Ester answered 21/1, 2019 at 11:7 Comment(0)
B
0

Installing pyserial (as opposed to serial) fixed the issue for me

Benbow answered 19/10, 2021 at 21:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.