在我的代码中,我尝试使用模块与一些设备进行交互serial:from serial import serialser = serial.Serial('/dev/ttyUSB0') # open serial portprint(ser.name) # check which port was really usedser.write(b'hello') # write a stringser.close()但我收到此错误:cannot import name 'serial' from 'serial' (unknown location)我在 Stack Overflow 上搜索了此错误消息,但找不到解决我问题的答案。根据我的发现,我尝试了:pip install serial,pip install pyserial,并卸载并重新安装。我该如何解决这个错误?
1 回答
ABOUTYOU
TA贡献1812条经验 获得超5个赞
试试这样:
from serial import Serial # note the capital S change
ser = Serial('/dev/ttyUSB0') # open serial port
print(ser.name) # check which port was really used
ser.write(b'hello') # write a string
ser.close()
添加回答
举报
0/150
提交
取消