Trying to send a message from my Pi to the Arduino via serial communication and I'm receiving this error despite having installed pyserial ImportError: cannot import name 'Serial' from 'serial' (/home/pi/serial.py)

When I change my code to import serial instead of from serial import Serial, the same error presents.

Wondering if anyone else has had this issue and you resolved it.

from serial import Serial
import time

if __name__ == '__main__':
    ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)

while True:
    ser.write(b"Hello from Raspberry Pi!\n")
    line = ser.readline().decode('utf-8').rstrip()
  • 2
    Not Pi specific. No details of the name of your Python module, nor of its contents. If you edit these details into your question it may reveal an obvious error.
    – joan
    Sep 20, 2020 at 16:30
  • Other thing to check is if you used pip or pip3 to install it. PIP is for Python 2.x and PIP3 is for Python 3.x. Remember on a Pi the command python fires up v2 still :-(
    – user115418
    Sep 20, 2020 at 16:51
  • Thing is I installed pyserial on all version of python (tried both commands pip and pip3. But I will double check Sep 20, 2020 at 20:24

1 Answer 1


It looks like your code file is named serial.py. Change it to something else!

If you name a file in the current working directory after a module, then Python will use that file in your current working directory than the modules installed.

  • Thanks. Changed the name but receiving the same error Sep 20, 2020 at 20:22
  • After changing the name it returns ImportError: cannot import name Serial Sep 20, 2020 at 20:25
  • 1
    @patriciajlim Remove any file with the name serial.pyc in your working directory.
    – joan
    Sep 20, 2020 at 22:03

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .