简体   繁体   English

Pyserial:“模块‘serial’没有‘tools’属性”

[英]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.我有一些设备通过RS485 到 USB 转换器连接到我的笔记本电脑,并希望在 python 程序中检测它们。

I'm running this Code with PyCharm Community Edition on a Windows 7 Notebook , I've installed pyserial with pip.我在Windows 7 Notebook 上使用PyCharm Community Edition运行此代码,我已经使用 pip 安装了 pyserial。

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'回溯(最近一次调用):文件“C:/Users/rzzrgx/.PyCharmCE2018.3/config/scratches/scratch_1.py”,第 3 行,在 x = list(serial.tools.list_ports.comports()) AttributeError :模块“串行”没有属性“工具”

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)

安装 pyserial(而不是串行)为我解决了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM