源代码如下 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