Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


I had the same problem several times while importing modules. I don't understand why it does work in some cases (for instance when you look at some examples in the serial website)

I tried. not work. The error will be "ImportError: cannot import name serial"

Note
Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


I had the same problem several times while importing modules. I don't understand why it does work in some cases (for instance when you look at some examples in the serial website)

I tried. not work. The error will be "ImportError: cannot import name serial"

This looks utterly wrong, sorry. At first the class is Serial not serial, then you don't have to import a class to use it. module.class() should work very fine. Last but not least there is no real explanation for what's going on here at all.

Note
Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


AttributeError: 'module' object has no attribute 'SerialException

Additional point for GAE users - try flushing memcache. Somehow ran into this and got stumped for ages after moving a model to a different file. Not sure what was cached that caused it, but it flush fixed it.

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.

Wow, didn't see that coming. Spent 45 minutes pulling hair out.

Note
Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


sudo python -m pip install pyserial
sudo python -m pip install serial

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

Note
Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


...looks like a bug to me...

If you are helpless like me, try this:

List all Sub-Modules of "Serial" (or whatever package you are having trouble with) with the method described here: List all the modules that are part of a python package

Note
Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


Note
Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


I had the same problem several times while importing modules. I don't understand why it does work in some cases (for instance when you look at some examples in the serial website)

I tried. not work. The error will be "ImportError: cannot import name serial"

This looks utterly wrong, sorry. At first the class is Serial not serial, then you don't have to import a class to use it. module.class() should work very fine. Last but not least there is no real explanation for what's going on here at all.

Note
Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


...looks like a bug to me...

If you are helpless like me, try this:

List all Sub-Modules of "Serial" (or whatever package you are having trouble with) with the method described here: List all the modules that are part of a python package

Note
Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


sudo python -m pip install pyserial
sudo python -m pip install serial

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

Note
Rectangle 27 1

Python AttributeError: 'module' object has no attribute 'Serial'?


AttributeError: 'module' object has no attribute 'SerialException

Additional point for GAE users - try flushing memcache. Somehow ran into this and got stumped for ages after moving a model to a different file. Not sure what was cached that caused it, but it flush fixed it.

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.

Wow, didn't see that coming. Spent 45 minutes pulling hair out.

Note