Skip to content Skip to sidebar Skip to footer

Python Attributeerror: 'module' Object Has No Attribute 'serial'

I'm trying to access a serial port with Python 2.6 on my Raspberry Pi running Debian. My script named serial.py tries to import pySerial: import serial ser = serial.Serial('/dev/tt

Solution 1:

I'm adding this solution for people who make the same mistake as I did.

In most cases: rename your project file 'serial.py' and delete serial.pyc if exists, then you can do simple 'import serial' without attribute error.

Problem occurs when you import 'something' when your python file name is 'something.py'.

Solution 2:

I accidentally installed 'serial' (sudo python -m pip install serial) instead of 'pySerial' (sudo python -m pip install pyserial), which lead to the same error.

If the previously mentioned solutions did not work for you, double check if you installed the correct library.

Solution 3:

You're importing the module, not the class. So, you must write:

from serial importSerial

You need to install serial module correctly: pip install pyserial.

Solution 4:

You have installed the incorrect package named 'serial'.

  • Run pip uninstall serial for python 2.x or pip3 uninstall serial for python 3.x
  • Then install pyserial if not already installed by running pip install pyserial for python 2.x orpip3 install pyserial for python 3.x.

Solution 5:

This problem is beacouse your proyect is named serial.py and the library imported is name serial too , change the name and thats all.

Post a Comment for "Python Attributeerror: 'module' Object Has No Attribute 'serial'"