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

good day, I am testing serial port communciation on raspberry pi 3 interface with SIM 900 module. The code are attached with error message. Thanks

import serial
import os, time
 
# Enable Serial Communication
port = serial.Serial("/dev/ttyS0", baudrate=38400, timeout=1)
 
# Transmitting AT Commands to the Modem
# '\r\n' indicates the Enter key
 
port.write('AT'+'\r\n')
rcv = port.read(10)
print (rcv)

>>> 
======================== RESTART: /home/pi/SIM900.py ========================
Traceback (most recent call last):
  File "/home/pi/SIM900.py", line 1, in <module>
    import serial
  File "/home/pi/serial.py", line 5, in <module>
    port = serial.Serial("/dev/ttyS0", baudrate=38400, timeout=1)
AttributeError: module 'serial' has no attribute 'Serial'
>>>
Rama TitoProgrammerAsked:
Who is Participating?
 
Flabio GatesCommented:
AttributeError: module 'serial' has no attribute 'Serial'
Are you sure the serial.py file in your "/home/pi/" folder is the module you want to import?
If not, then perhaps you have to rename it to something else.
0
 
Rama TitoProgrammerAuthor Commented:
Thank you, i did the following and manage to exist from that error : -
1. Rename script from serial.py to something else
2. Remove __pycache__ folder
3. After deletion of folder, serial.pyc was silently created so I deleted it too.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.