serial.tools.list_ports has to be imported specifically as the tools module is not automatically imported by the serial module.
i usually use
import serial.tools.list_ports
for info in serial.tools.list_ports.comports():
print(info)
不能导入serial,然后用serial.tools.的方式调用,否则会提示
AttributeError: module ‘serial’ has no attribute ‘tools’
正确的导入方法是import serial.tools.list_ports,然后使用serial.tools.list_ports.comports() 来读取串口信息
当然要首先安装 pyserial模块