2

TL, DR: A python file encounters the UnicodeDecodeError when ran in Spyder, but works when I ran it in command line.


I downloaded a Python module that wraps a C implementation of a suffix tree. After built, it was ran in Spyder but I got the following error:

runfile('F:/src/suffix_tree-2.1/build/lib.win32-2.7/suffix_tree.py', wdir='F:/src/suffix_tree-2.1/build/lib.win32-2.7') Traceback (most recent call last):

File "G:\IDE\python\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3052, in run_code self.showtraceback()

File "G:\IDE\python\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 1851, in showtraceback value, tb, tb_offset=tb_offset)

File "G:\IDE\python\Anaconda\lib\site-packages\IPython\core\ultratb.py", line 1240, in structured_traceback self, etype, value, tb, tb_offset, number_of_lines_of_context)

File "G:\IDE\python\Anaconda\lib\site-packages\IPython\core\ultratb.py", line 1157, in structured_traceback self, etype, value, elist, tb_offset, number_of_lines_of_context

File "G:\IDE\python\Anaconda\lib\site-packages\IPython\core\ultratb.py", line 511, in structured_traceback lines = ''.join(self._format_exception_only(etype, value))

File "G:\IDE\python\Anaconda\lib\site-packages\IPython\core\ultratb.py", line 623, in _format_exception_only Colors.Normal, s))

UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 20: ordinal not in range(128)

This error appears right after I import _suffix_tree.pyd, even before any other operations.

However, if I run the file in command line (cmd), it works successfully without any error.

PS: I use Windows, and my user name are ASCII characters.

4
  • Don't know if this help, probably not but have you tried to put # -- coding: utf-8 -- on the very top of the file (before imports)? Commented Aug 13, 2015 at 17:08
  • It doesn't unfortunately. :-( Commented Aug 13, 2015 at 17:16
  • I had a similar problem (I have an accent in my username). I used Anaconda3 to solve it. Commented Aug 13, 2015 at 17:20
  • Thanks @clemtoy. I thought it was an issue in Spyder, since my file works in PyCharm. I will try Anaconda3 too. Commented Aug 13, 2015 at 17:24

1 Answer 1

1

You are possibly trying to open a file encoded in a different format of your system, you should check it and set Spyder using the commands below.

import sys  
reload(sys)  
sys.setdefaultencoding('utf8')

If this does not work, check the version of the Python kernel of the program. You can get this message trying to run an Python 3 code in an Spyder 2.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.