[英]how do i fix the error in this python code
獲取我正在運行的代碼的返回錯誤。 因為這是復制的代碼,所以我沒有編寫它,也不知道如何修復它。 OP WINDOWS 10 anaconda3 python 3.7.6
代碼:
#Purpose: Save data from an arduino into file using python
#Name: Kira Kemock
#Date: 7/24/2020
#filename = myfile.txt
import serial ****LINE 5*****
port_addr='COM4' # com port of the arduino
baud='9600'
file_name='mydata.txt' # this file will be saved in the same location as the py file
with serial.Serial(port_addr,baud) as port, open(file_name,"w+", 256) as outf:
for i in range(200): #read 200 lines into the file
fullline = port.readline()
line = str(fullline)
outf.write(line)
outf.write('\n')
outf.flush()
返回:
runfile('C:/PythonCode/SaveSerial.py', wdir='C:/PythonCode', post_mortem=True)
Traceback (most recent call last):
File "C:\PythonCode\SaveSerial.py", line 5, in <module>
import serial
ModuleNotFoundError: No module named 'serial'
第 5 行已標有第 5行 * 以幫助識別問題
你需要安裝串口。 你可以用
pip3 install serial
打開 powershell 並輸入
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.