Luis Ramon Ramirez Rodriguez Luis Ramon Ramirez Rodriguez - 5 months ago 10
Python Question

'module' object has no attribute 'Serial'

I'm using the following code to communicate my pc with an arduino, but I get the error mentioned in the title, module objet has no attribute Serial.


# Importamos la libreira de PySerial
import serial

# Abrimos el puerto del arduino a 9600
PuertoSerie = serial.Serial('/dev/ttyACM0', 9600)
# Creamos un buble sin fin
while True:
# leemos hasta que encontarmos el final de linea
sArduino = PuertoSerie.readline()
# Mostramos el valor leido y eliminamos el salto de linea del final
print "Valor Arduino: " + sArduino.rstrip('\n')

The curios thing is the the code used to work, but then I installed matplotlib and drawnow libraries, I believe that has caused the problem but I don't know how to fix it, because and need those libraries any way.

The other matter is that is I copy the code line to line into the terminal it works but of course I need I with the loop in a .py file.


The solution is to not name the source file since in such case Python takes that instead of the actually desired serial module.

(Since the question was solved in the comments and no answer has been posted, inspired by a relevant meta question I'm adding this answer to make the question complete. I'm not trying to get credit for deets' solution and I'm posting it as a community wiki answer.)