TL,DR:Python文件遇到的UnicodeDecodeError時Spyder的跑,但是當我在命令行運行它的工作原理。Spyder的 - Python的 - 的UnicodeDecodeError: 'ASCII' 編解碼器不能解碼
我下載了一個包含後綴樹的C實現的Python module。建成後,它跑了Spyder的,但我得到了以下錯誤:
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)
此錯誤出現之後我進口_suffix_tree.pyd,甚至在任何其他操作。
但是,如果我在命令行(cmd)中運行該文件,它可以正常工作而不會出現任何錯誤。
PS:我使用Windows,我的用戶名是ASCII字符。
不知道這是否有幫助,可能不是,但你有沒有嘗試把## - * - coding:utf-8 - * - on文件的頂部(導入之前)? –
它並不幸運。 :-( – CodeRush
我有[類似的問題](http://stackoverflow.com/questions/31525150/remove-accents-in-windows-username-causing-troubles-with-softwares-and-libraries)(我有一個口音在我的用戶名)我使用Anaconda3解決它 – clemtoy