串口:AttributeError: module ‘serial‘ has no attribute ‘Serial‘

串口:AttributeError: module ‘serial‘ has no attribute ‘Serial‘,第1张

import serial
with serial.Serial('COM4', 9600) as ser: 

Traceback (most recent call last):
  File "d:/111 孙 学习相关/python/serial.py", line 1, in 
    import serial
  File "d:\111 孙 学习相关\python\serial.py", line 4, in 
    with serial.Serial('COM4', 9600, timeout=1) as ser: #延时查询串口1秒钟

AttributeError: module 'serial' has no attribute 'Serial'

遇到此问题:

1.不能用serial.py作为代码名字。貌似是不能用模块名作为代码名字。

2.卸载serial,安装pyserial,重新打开编辑器

pip uninstall serial
pip uninstall pyserial
pip install pyserial

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/904883.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-15
下一篇2022-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存