Python attributeError: module 'serial' has no attribute 'Serial'
Python attributeError: module 'serial' has no attribute 'Serial'
我在 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
,它开始工作了。
我在 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
,它开始工作了。