環境
- Windows 10 64bit
- Python 3.6.3
- xonsh:
xonsh/0.6.0
事象
サブプロセスモードの何かしらで<TAB>
で補完を試みると、下記のエラー
Exception in thread Thread-25:
Traceback (most recent call last):
File "C:\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Python36\lib\subprocess.py", line 1063, in _readerthread
buffer.append(fh.read())
UnicodeDecodeError: 'cp932' codec can't decode byte 0x83 in position 14: illegal multibyte sequence
Exception in thread Thread-24:
Traceback (most recent call last):
File "C:\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Python36\lib\site-packages\prompt_toolkit\interface.py", line 865, in run
completions = list(buffer.completer.get_completions(document, complete_event))
File "C:\Python36\lib\site-packages\xonsh\ptk\completer.py", line 49, in get_completions
self.ctx)
File "C:\Python36\lib\site-packages\xontrib\free_cwd.py", line 82, in wrapper
out = func(*args, **kwargs)
File "C:\Python36\lib\site-packages\xonsh\completer.py", line 35, in complete
out = func(prefix, line, begidx, endidx, ctx)
File "C:\Python36\lib\site-packages\xonsh\completers\bash.py", line 13, in complete_from_bash
command = xp.bash_command()
File "C:\Python36\lib\site-packages\xonsh\platform.py", line 432, in bash_command
bc = windows_bash_command()
File "C:\Python36\lib\site-packages\xonsh\platform.py", line 340, in windows_bash_command
universal_newlines=True)
File "C:\Python36\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Python36\lib\subprocess.py", line 405, in run
stdout, stderr = process.communicate(input, timeout=timeout)
File "C:\Python36\lib\subprocess.py", line 843, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "C:\Python36\lib\subprocess.py", line 1113, in _communicate
stdout = stdout[0]
IndexError: list index out of range
原因
locale.getpreferredencoding()
がcp932
になっているので、Unicodeの文字をcp932
でdecode
しようとしてる。(多分)
import locale
locale.getpreferredencoding()
\# => 'cp932'
対策
無理やりlocale.getpreferredencoding()
を変更する
~/.xonshrc
に以下を追記 (参考@stackoverflow)。
import _locale
_locale._getdefaultlocale = (lambda *args: ['ja_JP', 'utf_8'])