pip install & UnicodeDecodeError: 'utf-8'

2020-03-30 08:59发布

问题:

Try install:

pip install python-binance

Result:

Exception:
Traceback (most recent call last):
  File "c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
    return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 9: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\commands\install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_set.py", line 634, in _prepare_file
    abstract_dist.prep_for_dist()
  File "c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_set.py", line 129, in prep_for_dist
    self.req_to_install.run_egg_info()
  File "c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_install.py", line 439, in run_egg_info
    command_desc='python setup.py egg_info')
  File "c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
    return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 9: invalid continuation byte

How to solve?

回答1:

OKAY...

  1. Since the error was in my file:

    c:\users\анна\appdata\local\programs\python\python36\lib\site-packages\pip\compat__init__.py

The problem folder was 'анна' which was is cp1251

  1. The first solution is to find how to rename the user's folder. (except for reinstalling the operating system). To the folder with the Latin alphabet

  2. The second path in the file compat__init__.py - replace

    return s.decode(sys.__stdout__.encoding)

  3. into

    return s.decode('cp1251')

Of course you need to know what encoding you have. At me it cp1251, at you it can be latin (for an example). After the replacement in the file - everything was installed successfully!

Thanks 2 cowbert



回答2:

I suggest using quick fix for such situations. The fix is done by redirecting the output from standard direction (terminal) to file like this:

pip install python-binance > temp_output_file

and open it if you need...



标签: python pip