我已经在这里寻找了类似的解决方案,但是我能找到的唯一的解决方案不能解决问题,并且像这个python module 'serial' has no attribute 'Serial' [duplicate]这样的解决方案没有得到解决。
这段代码
self.ser = serial.Serial(port=self.dev_path, baudrate=600, bytesize=8, parity='N', stopbits=1, timeout=None)给出了错误
AttributeError: module 'serial' has no attribute 'Serial'我正在将序列导入为
import serial然而,其他解决方案建议使用
from serial import Serial它会给出错误
NameError: name 'serial' is not defined编辑完整代码:
def __init__(self, debugging=False):
# self.ser = serial.Serial(port='/dev/ttyUSB0',baudrate=600, bytesize=8, parity='N', stopbits=1, timeout=None)
self.ser = serial.Serial(port=self.dev_path, baudrate=600, bytesize=8, parity='N', stopbits=1, timeout=None)
print(str(self.ser.name))
self.status()
self.debug = debugging
if (self.debug):
print(self.ser.name)
print("Pulse: " + str(self.pulse) + "\n")
def __del__(self):
self.ser.close()发布于 2018-12-18 21:58:37
也许您已经安装了the serial package序列化/反序列化JSON/YAML/XML到python类实例,反之亦然,而不是用于访问串行端口的pySerial package?
尝试卸载serial程序包并安装pyserial程序包:
pip uninstall serial
pip install pyserial还要确保您的文件名不是serial.py。在这种情况下,import serial将只导入您自己的文件。
发布于 2019-04-26 01:57:06
我刚刚遇到了这个问题,对我来说,在尝试任何东西之前,它都与通过pyserial导入serial有关。为了补救,我必须执行以下操作:
pip uninstall serial
pip uninstall pyserial
pip install pyserial在那之后,它就像一个护身符一样起作用。
https://stackoverflow.com/questions/53834584
复制相似问题