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

0 votes

I have a Raspberry Pi running on Debian, and I've been trying to access one of its serial ports with a python script, where I try to import pySerial like this:

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

But I still can't establish the serial connection as executing the script just throws the following error:
AttributeError: 'module' object has no attribute 'Serial'

And what is weirder is that it used to work earlier and now it doesn't even work in the interactive Python interpreter.
I've tried reinstalling the pySerial again and even rewritten the code multiple times to ensure that it's correct but had no luck yet. 

Can anybody please tell me where I could be going wrong? Or, just point me in right direction? Please help. TIA! 

Aug 14, 2018 in IoT (Internet of Things) by Bharani
• 4,550 points
1,473 views

1 answer to this question.

0 votes

I see where the problem is. I faced the same issue while trying to import modules myself. While it does work in some cases, it just won't in others.
But anyways, what I essentially learned is that since it is the entire module you're trying to import and not just a class, you'll need to write: from serial import serial

answered Aug 14, 2018 by DataKing99
• 8,130 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Issues with Intel Edison MRAA module

You can work on this choice:- In the ...READ MORE

answered Jul 11, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
48 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to send a data from arduino uno to a webpage through esp8266 wifi module?

You are missing a few \r\n and the length ...READ MORE

answered Aug 9, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
1,346 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 240 views
0 votes
1 answer

Connecting GSM Module to Raspberry Pi 2

Hey, just use any 'supported' USB-to-Serial adapter ...READ MORE

answered Nov 22, 2018 in IoT (Internet of Things) by DataKing99
• 8,130 points
156 views