Doubt with Pyserial on Mac


My problem is this, I just bought a MacBook Pro computer, I used to use Windows 10 to do Python practices, connecting it to Arduino using the Pyserial which was included in the Pycharm program. Now that I am suando Mac the program Pycharm does not recognize me the port that identifies me as arduino, in this case it is:

"/ dev / cu.usbmodem1421"

At the time of compiling, I get the following error:

"SyntaxError: Non-ASCII character '\xc2' in file 
/Users/StoomBassCow/PycharmProjects/untitled1/aperro/ on line 4,
but no encoding declared; see for details"

Someone who can explain to me what the problem is?

My code is:

# -*- coding: utf-8 -*-

import sys

print sys.getdefaultencoding()

import serial

puertoserie = serial.Serial('/dev/cu.usbmodem1421',9600)

while True:
    tecla = input("Presiona la tecla 1 para encender el led")

    if tecla.lower() == 'e':    
asked by StoomBassCow 15.07.2016 в 04:17

1 answer


Since you are using the header # -*- coding: utf-8 -*- and I do not see any strange characters, I can only imagine that the failure is due to some space in another encoding. So try eliminating all the spaces, especially those of the line that you mention in the error, also re-devise it but using only blank spaces instead of tabs.

answered by 15.07.2016 в 06:17