Thefuck: 'UnicodeDecodeError' on windows powershell

Created on 3 Aug 2017  路  5Comments  路  Source: nvbn/thefuck

Below are the warning and error when i execute command fuck

 RuntimeWarning: sys.stdin.encoding == 'utf-8', whereas sys.stdout.encoding == 'cp936', readline hook consumer may assume they are the same
  readline_hook.enable(use_pyreadline=use_pyreadline)
Traceback (most recent call last):
  File "d:\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Anaconda3\Scripts\thefuck.exe\__main__.py", line 9, in <module>
  File "d:\anaconda3\lib\site-packages\thefuck\main.py", line 51, in main
    fix_command(known_args)
  File "d:\anaconda3\lib\site-packages\thefuck\main.py", line 27, in fix_command
    command = types.Command.from_raw_script(raw_command)
  File "d:\anaconda3\lib\site-packages\thefuck\types.py", line 125, in from_raw_script
    stderr = result.stderr.read().decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 6: invalid start byte

Most helpful comment

I am having the same issue with PYTHONIOENCODING set to utf-8.

I wonder if thefuck reads the stdout so any non-utf-8 chars will break this.

PS: I am running thefuck on Python3.7 on a Chinese Windows system.

Solution:

Add this line to profile:

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

All 5 comments

I had the same issue as well.

  • Add an environment variable PYTHONIOENCODING=utf-8
  • OR change your $PROFILE from
    Powershell iex "$(thefuck --alias)"
    to
    Powershell $env:PYTHONIOENCODING="utf-8" iex "$(thefuck --alias)"

Thanks, worked like a charm.

That didn't work for me. I've set the environment variable, but no success.

I've even reinstalled thefuck with pip, with the environment variable already set. I was hoping that executing the whole python import thefuck with the correct encoding would solve the issue, but no.

So, waiting for more suggestions.

Btw, fuck executes like this, after no commands at all, or after wrong calls like fick; right calls like ls or Get-ChildItem-Color.

If I execute after git stats, fuck will work like a charm.

I am having the same issue with PYTHONIOENCODING set to utf-8.

I wonder if thefuck reads the stdout so any non-utf-8 chars will break this.

PS: I am running thefuck on Python3.7 on a Chinese Windows system.

Solution:

Add this line to profile:

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Was this page helpful?
0 / 5 - 0 ratings

Related issues

whereistejas picture whereistejas  路  4Comments

yuanwenq picture yuanwenq  路  5Comments

agross picture agross  路  5Comments

pizzathief picture pizzathief  路  6Comments

onewheelskyward picture onewheelskyward  路  3Comments