[英]'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. 我正在使用以下代码与arduino通信我的电脑,但我得到标题中提到的错误,模块对象没有属性串行。
#!/usr/bin/python
# 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. 古玩的事情是用来工作的代码,但后来我安装了matplotlib和drawow库,我相信这已经引起了问题,但我不知道如何修复它,因为并且需要这些库的任何方式。
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. 另一个问题是我将代码行复制到它工作的终端中,但当然我需要在.py文件中使用循环。
The solution is to not name the source file serial.py
since in such case Python takes that instead of the actually desired serial
module. 解决方案是不将源文件命名为serial.py
因为在这种情况下,Python取代了实际需要的serial
模块。
(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.) (由于这个问题已在评论中得到解决,并且没有发布任何答案,受到相关元问题的启发,我正在添加此答案以使问题完整。我不是想要得到deets解决方案的信任而且我是将其发布为社区维基答案。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.