mieckhar
mieckhar

Reputation: 111

Pyserial: "module 'serial' has no attribute 'tools'"

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'

Upvotes: 7

Views: 13390

Answers (2)

laurakoco
laurakoco

Reputation: 59

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

Upvotes: 0

jia Jimmy
jia Jimmy

Reputation: 1848

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)

Upvotes: 17

Related Questions