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

源代码如下

import serial 
t=serial.Serial(0)
print t.portstr
while True:
    str=t.read(1)
    if str:
        print str

运行时出现如下错误

AttributeError: 'module' object has no attribute 'Serial'
无奈,问google吧,文章有点少。看到有人说改成这样就可以了

from serial import *
t=Serial(0)
print t.portstr
while True:
    str=t.read(1)
    if str:
        print str

上面的错误没有了,可是新的错误出现了

没有serial模块!

继续google吧!没办法!

好多都是英文,看着费劲啊!

看这网页挺不错的,感觉比较好,耐心看看英文吧

I'm adding this solution for people who make the same mistake as I did.

In most cases: rename your project file 'serial.py' and delete serial.pyc if exists, then you can do simple 'import serial' without attribute error.

Problem occurs when you import 'something' when your python file name is 'something.py'.

就是这段话,哈哈!

我把文件明明名成serial.py运行后自己又生成一个serial.pyc的文件。把这个serial.pyc文件删除,将原来的serial.py改成aaaa.py再次运行OK!大笑

原地址:http://stackoverflow.com/questions/11403932/python-attributeerror-module-object-has-no-attribute-serial


  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值