繁体   English   中英

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

[英]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.

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