AttributeError: 'module' object has no attribute 'Serial'
2013-09-09 15:29
651 查看
源代码如下
import serial
t=serial.Serial(0)
print t.portstr
while True:
str=t.read(1)
if str:
print str
运行时出现如下错误
无奈,问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://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)
原地址:http://stackoverflow.com/questions/11403932/python-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://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)
原地址:http://stackoverflow.com/questions/11403932/python-attributeerror-module-object-has-no-attribute-serial
相关文章推荐
- Scrapy安装报错:AttributeError: 'module' object has no attribute 'OP_NO_TLSv1_1'解决办法
- 使用cx_freeze工具打包时提示 AttributeError 'module' object has no attribute '_fix_up_module':
- [python错误]builtins.AttributeError: 'module' object has no attribute 'request'
- python3 报错: AttributeError: 'module' object has no attribute 'urlopen'
- ImportError: ‘module’ object has no attribute 'check_spec...'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- AttributeError: 'module' object has no attribute 'Serial'
- Python 使用sqlite3报错 AttributeError: 'module' object has no attribute 'connect'
- Python AttributeError: ‘module’ object has no attribute ‘A’
- service_identity 模块 AttributeError: 'module' object has no attribute 'Any'
- AttributeError: 'module' object has no attribute 的解决方法
- 解决Python报错: AttributeError: 'module' object has no attribute '_base'
- Tensorflow报错:AttributeError: 'module' object has no attribute 'summary'
- Python Matplotlib AttributeError: 'module' object has no attribute 'popall'
- AttributeError: 'module' object has no attribute 'AF_INET'处理办法——python
- 【python学习笔记(2)】脚本报错"AttributeError: 'module' object has no attribute 'xxx'"解决方法
- AttributeError: 'module' object has no attribute 'maketrans'
- Python 错误:AttributeError: 'module' object has no attribute
- Importing theano: AttributeError: 'module' object has no attribute 'find_graphviz'
- Django报错:AttributeError: 'module' object has no attribute 的解决方法