I don’t know much about python, but I had to use it. I installed the serial library via pip3, everything went smoothly, the 'import serial' error does not produce errors, but in this code:

import serial r = serial.Serial('com3', 9600) f = open('C:\statistic\stat.txt', 'w') e = 0 while(e == 0): t = int(r.readline()) print(t) f.write(str(t)) f.close() 

gives an error message:

File "", line 1, in
ser = serial.Serial ('COM3')
AttributeError: module 'serial' has no attribute 'Serial'

  • did you accidentally name your file serial.py ? - jfs

1 answer 1

Install pyserial , not serial .

 >> pip install pyserial 

UPDATE !!!

There may be another solution, as in the following question: https://stackoverflow.com/questions/11403932/python-attributeerror-module-object-has-no-attribute-serial?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

The point is that you have to import the module, like this: from serial import serial

By the way, pay attention to this answer as well: Problem occurs when you import 'something' when your python file name is 'something.py' .
It is understood that the name of your file must be different from the modules imported in this file.