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

Rama Tito
Rama Tito used Ask the Experts™
on
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'
>>>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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.
Rama TitoProgrammer

Author

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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial