简体   繁体   English

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

[英]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.

相关问题 AttributeError: 模块 'serial' 没有属性 'Serial' - AttributeError: module 'serial' has no attribute 'Serial' pySerial AttributeError:模块'serial'没有属性'Serial' - pySerial AttributeError: module 'serial' has no attribute 'Serial' Python - 模块“串行”没有属性“串行” - Python - module 'serial' has no attribute 'Serial' 如何解决 AttributeError:模块 'serial' 在 pyserial 中没有属性 'Serial'? - How to solve AttributeError: module 'serial' has no attribute 'Serial' in pyserial? Serial.serial 不起作用,thonny:模块 'serial' 没有属性 'Serial' - Serial.serial is not working, thonny: module 'serial' has no attribute 'Serial' AttributeError:模块 'serial' 没有属性 'reset_input_buffer' - AttributeError: module 'serial' has no attribute 'reset_input_buffer' AttributeError: 'module' 对象没有属性 'Serial' 与 pi 和 arduino 的连接 - AttributeError: 'module' object has no attribute 'Serial' with connection for pi and arduino 'module'对象没有属性'Serial' - 'module' object has no attribute 'Serial' Pyserial:“模块‘serial’没有‘tools’属性” - Pyserial: "module 'serial' has no attribute 'tools'" PySerial Python 错误:AttributeError: 'Serial' 对象没有属性 '_port_handle' - PySerial Python error: AttributeError: 'Serial' object has no attribute '_port_handle'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM