本文介绍了串行导入python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用pyserial.执行以下脚本时.
I"m trying to use pyserial. When I do the following script.
import serial
ser= serial.serial("COM5", 9600)
ser.write("Hello worldn")
x = ser.readline()
print(x)
错误代码:
c:\Python27>python com.py
Traceback (most recent call last):
File "com.py", line 2, in <module>
ser= serial.serial("COM5", 9600)
AttributeError: 'module' object has no attribute 'serial'
我阅读了一条建议并将其更改为:
I read a suggestion and changed it to:
from serial import serial
ser= serial.serial("COM5", 9600)
ser.write("Hello worldn
x = ser.readline()
print(x)
我现在得到了错误
c:\Python27>python com.py
Traceback (most recent call last):
File "com.py", line 1, in <module>
from serial import serial
ImportError: cannot import name serial
我了解到这可能是由于模块中包含 ini 而引起的,但是对此一无所知.
I read that this can be from having ini in your module, but dont' know anyting about this.
我打印了sys.path,并且pyserial在其中.
I printed my sys.path and pyserial is in there.
['C:\\Users\\Jeff\\Desktop', 'C:\\Python27\\lib\\site-packages\\distribute-0.6.4
9-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pyserial-2.7-py2.7.egg', 'C:\\W
indows\\SYSTEM32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\
\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Pyt
hon27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11
-py2.7.egg-info']
有点生气:(...感谢您的帮助.
Getting kind of annoyed :(... Thanks for help.
推荐答案
应为:
import serial
ser = serial.Serial("COM5", 9600)
请注意序列中的大写字母"S"
Note the capital 'S' in serial.Serial
这篇关于串行导入python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!