Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'

like image 563
mieckhar Avatar asked Jan 21 '19 10:01

mieckhar


People also ask

How do I know if Pyserial is installed?

To check that it is installed, start Pyzo and at the command prompt type in: import serial If it just gives you another >>> prompt, all is good. Checking that it is really working.

What is Pyserial module?

PySerial is a library which provides support for serial connections ("RS-232") over a variety of different devices: old-style serial ports, Bluetooth dongles, infra-red ports, and so on. It also supports remote serial ports via RFC 2217 (since V2. 5).

Does Pyserial work on Windows?

Install PySerialIf you are using windows you need to uncompress this into a folder. Unfortunately, it is not a normal zip file, so you may need to download a tool such as 7-zip (http://www.7-zip.org/). If you are using a Mac or Linux computer, then open a Terminal session, 'cd' to wherever you downloaded pyserial-2.6.


1 Answers

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)

like image 139
jia Jimmy Avatar answered Oct 09 '22 09:10

jia Jimmy