在我的代碼中,我嘗試使用模塊與一些設備進行交互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
提交
取消