Python AttributeError: 'module' object has no attribute 'Serial' -


I am trying to use a serial port with Python 2.6 on Debian running on my Raspberry P My script tries to import named serial.py pySerial:

  import serial ser = serial.Serial ('/ dev / ttyAMA0', 9600) ser. Write ("hello world!")   

For some reason it denies establishing a serial connection with this error:

  AttributeError: 'module 'Object does not have any attribute' serial '  

When I try to write the same code in the interactive Python interpreter, it still does not work.

Strangely, it used to work about a few hours before.

What could be the problem? I have tried to fix it for a little while, re-installing picarial, re-writing my code, checking serial ports etc.

Thanks in advance!

You are importing the module, not the class. Therefore, you have to write: from serial import serial

Comments