我在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中的所有其他样本,它们是相同的,我不能使用它们中的任何一个。
答案 0 :(得分:5)
哈!
问题是我的文件名。我和我的python包使用相同的文件名!
我将文件名从serial.py
更改为test.py
,然后就开始工作了。