python - Pyserial: "module ' serial' 没有属性 'tools' "

标签 python python-3.x pyserial

我有一些设备通过 RS485 到 USB 转换器 连接到我的笔记本电脑,并想在 python 程序中检测它们。

我在 Windows 7 笔记本电脑上使用 PyCharm Community Edition 运行此代码,我已经使用 pip 安装了 pyserial。

导入序列号

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

并得到这个错误:

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'

最佳答案

导入方式不对,修改如下:


from serial.tools import list_ports

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


import serial.tools.list_ports

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

关于python - Pyserial: "module ' serial' 没有属性 'tools' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54288475/

相关文章:

python - Pandas 将不同大小的数据帧连接到列末尾

python - 打印循环的 PyQt4 Gui

python - ValueError : x and y must have the same first dimension

python - 在 Python 中对多维字典进行排序

python - 在 Python 中使用 try/except 将字符串转换为 Int

Django 1.11 管理员 : Create a OneToOne relationship and it's object in the admin

python - 在python 3中导入,请解释输出

python - 在 pySerial (Windows) 中查找特定的串行 COM 端口

python - PySerial Readline 进入无限循环

python - 将 .DAT 文件导入 Pandas 数据框