在我的代码中,我尝试使用serial
模块与某些设备进行交互:
from serial import serial
ser = serial.Serial('/dev/ttyUSB0') # open serial port
print(ser.name) # check which port was really used
ser.write(b'hello') # write a string
ser.close()
但是我得到这个错误:
cannot import name 'serial' from 'serial' (unknown location)
我在堆栈溢出中搜索了此错误消息,但是找不到解决我问题的答案。
根据发现的内容,我尝试了:
pip install serial
,pip install pyserial
,如何解决此错误?
答案 0 :(得分:0)
尝试一下:
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()