简体   繁体   中英

`Serial` attribute missing with the pyserial library (ubuntu 16.04 with python 2.7)

import serial 

ser = serial.Serial("/dev/ttyACM0", baudrate = 9600, timeout=1)

while 1:

    Data = ser.readline().decode('ascii')
print(Data)

Error: AttributeError: 'module' object has no attribute 'Serial'

You're importing the module, not the class. So, you have to use:

from serial import serial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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