Help us understand the problem. What is going on with this article?

xonshのタブ補完でなんかエラーになる件

More than 1 year has passed since last update.

環境

  • 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の文字をcp932decodeしようとしてる。(多分)

import locale

locale.getpreferredencoding()
\# => 'cp932'

対策

無理やりlocale.getpreferredencoding()を変更する

~/.xonshrcに以下を追記 (参考@stackoverflow)。

import _locale
_locale._getdefaultlocale = (lambda *args: ['ja_JP', 'utf_8'])
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした