简体   繁体   English

如何修复此 python 代码中的错误

[英]how do i fix the error in this python code

getting the return error for the code that I am running.获取我正在运行的代码的返回错误。 since this is a copied code I did not write it and am not sure how to fix it.因为这是复制的代码,所以我没有编写它,也不知道如何修复它。 OP WINDOWS 10 anaconda3 python 3.7.6 OP WINDOWS 10 anaconda3 python 3.7.6

CODE:代码:

#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()

RETURN:返回:

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'

LINE 5 HAS BEEN MARKED WITH LINE 5 * IN ORDER TO HELP IDENTIFY THE ISSUE第 5 行已标有第 5行 * 以帮助识别问题

You need to install serial.你需要安装串口。 you can do it with你可以用

pip3 install serial

Open powershell and type this打开 powershell 并输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM