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,071 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,100 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
37 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,093 views
0 votes
1 answer
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
56 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,100 points
107 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.