[英]Python attributeError: module 'serial' has no attribute 'Serial'
I am using Python3 in Windows 7 and I installed pyserial 3.3. 我在Windows 7中使用Python3,并安装了pyserial 3.3。 I create a file named serial.py with these line codes:
我使用以下行代码创建一个名为serial.py的文件:
import serial
ser = serial.Serial('COM4', 9600, timeout=0)
ser.write(b'mymessage')
it will show this error message: 它将显示此错误消息:
attributeError: module 'serial' has no attribute 'Serial'
for all other samples in their documentation it's same, and I could not use any of them. 对于其文档中的所有其他示例都是相同的,我无法使用它们中的任何一个。
Hah! 哈哈!
the problem was my filename. 问题是我的文件名。 I was using same file name with my python package!
我在python包中使用了相同的文件名!
I changed my filename from serial.py
to test.py
and it start working. 我将我的文件名从
serial.py
更改为test.py
,它开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.