Python attributeError:模块“ serial”没有属性“ Serial”

Rez*_*mya 1 python serial-port pyserial

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

import serial

ser = serial.Serial('COM4', 9600, timeout=0)
ser.write(b'mymessage')
Run Code Online (Sandbox Code Playgroud)

它将显示此错误消息:

attributeError: module 'serial' has no attribute 'Serial'
Run Code Online (Sandbox Code Playgroud)

对于其文档中的所有其他示例都是相同的,我无法使用其中的任何一个。

Rez*_*mya 5

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