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,660 points
9,786 views

2 answers to this question.

+1 vote

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,240 points
from serial import serial
ImportError: cannot import name 'serial' from 'serial' (/home/pi/Desktop/serial.py)

Hey, @karan,

Will you check, have you created a file called serial.py at any point and put it in an import location.

I had the same problem and then I realized that I had a file called serial, it was the error, now it works for me, thanks
0 votes
I also write from serial import Serial but still it shows error
answered Aug 12, 2020 by anonymous

Hi, @There,

Could you please mention what error you are facing?

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,280 points
763 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,280 points
3,429 views
0 votes
1 answer
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,007 views
0 votes
1 answer
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,240 points
827 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP