Skip to main content
 首页 » 编程设计

Python 属性错误 : module 'serial' has no attribute 'Serial'

2025年05月04日25虾米姐

我在 Windows 7 中使用 Python3,并安装了 pyserial 3.3。我使用这些行代码创建了一个名为 serial.py 的文件:

import serial 
 
ser = serial.Serial('COM4', 9600, timeout=0) 
ser.write(b'mymessage') 

它将显示此错误消息:

attributeError: module 'serial' has no attribute 'Serial' 

对于他们的所有其他样本 documentation都是一样的,我无法使用它们中的任何一个。

请您参考如下方法:

哈!
问题是我的文件名。我在我的 python 包中使用了相同的文件名!
我将文件名从 serial.py 更改为 test.py,它开始工作了。