Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non Ascii character error when using compiled code

Tags:

python

I have a python code which runs perfectly and I compiled it using py_compile.compile. The compile operation also worked nicely without any errors.

However, when I use this pyc file I get an error like

File "E:/tech/tech.pyc", line 1
    SyntaxError: Non-ASCII character '\xf3' in file E:/tech/tech.pyc on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

My question is how do I debug this error? The first line in my script is import os. I tried using

#!/usr/bin/python

It does not help either. Any suggestions on how this can be debugged?

like image 712
user741592 Avatar asked Jun 29 '26 14:06

user741592


1 Answers

You're doing something wrong. Please show your code. '\xf3' looks a lot like the pyc magic number to me (assuming you're using python 2.7):

>>> import imp
>>> imp.get_magic()
'\x03\xf3\r\n'

Are you trying to compile a pyc file (as if it were python source code)?

like image 114
Seth Avatar answered Jul 02 '26 04:07

Seth