e1ven/Robohash

"UnicodeDecodeError: 'charmap' codec can't decode byte 0x9f in position 1732" during pip install in Windows

Closed this issue · 2 comments

mrts commented
with open('README.rst') as file:
    long_description = file.read()

will fail in Windows in Git Bash with the following error:

$ pip install -r requirements.txt                                                                               Collecting git+https://github.com/e1ven/Robohash.git (from -r backend/requirements.txt (line 24))
  Cloning https://github.com/e1ven/Robohash.git to c:\users\foo\appdata\local\temp\pip-req-build-csx0_u6g
  Running command git clone -q https://github.com/e1ven/Robohash.git 'C:\Users\foo\AppData\Local\Temp\pip-req-build-csx0_u6g'
    ERROR: Command errored out with exit status 1:
     command: 'c:\devel\other\heedview\venv\scripts\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\foo\\AppData\\Local\\Temp\\pip-req-build-csx0_u6g\\setup.py'"'"'; __file__='"'"'C:\\Users\\foo\\AppData\\Local\\Temp\\pip-req-build-csx0_u6g\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: C:\Users\foo\AppData\Local\Temp\pip-req-build-csx0_u6g\
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\foo\AppData\Local\Temp\pip-req-build-csx0_u6g\setup.py", line 7, in <module>
        long_description = file.read()
      File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\encodings\cp1257.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x9f in position 1732: character maps to <undefined>
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Windows Git Bash uses cp1257 encoding by default, README contains Unicode emoji that doesn't have a mapping in cp1257, hence the error.

Fix is simple, use

with open('README.rst', encoding='utf-8') as file:
mrts commented

@e1ven note that open with encoding breaks Python 2.7 compatibility

A simple solution is to modify your requirement.txt file by removing version number of python-stdnum package
before:
python-stdnum==1.8
after:
python-stdnum