在我的代碼中,我嘗試使用模塊與一些設(shè)備進(jìn)行交互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()但我收到此錯(cuò)誤:cannot import name 'serial' from 'serial' (unknown location)我在 Stack Overflow 上搜索了此錯(cuò)誤消息,但找不到解決我問(wèn)題的答案。根據(jù)我的發(fā)現(xiàn),我嘗試了:pip install serial,pip install pyserial,并卸載并重新安裝。我該如何解決這個(gè)錯(cuò)誤?
1 回答

ABOUTYOU
TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
試試這樣:
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()
添加回答
舉報(bào)
0/150
提交
取消