pythonprofilers / memory_profiler

Monitor Memory usage of Python code
http://pypi.python.org/pypi/memory_profiler
Other
4.39k stars 380 forks source link

UnicodeDecodeError while running setup.py #341

Closed sg495 closed 2 years ago

sg495 commented 2 years ago

While installing memory_profiler-0.59.0.tar.gz with pip install memory-profiler, I noticed the following error:

>pip install memory-profiler
Collecting memory-profiler
  Downloading memory_profiler-0.59.0.tar.gz (38 kB)
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
  [...]
  Complete output (7 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "[...]\setup.py", line 33, in <module>
      long_description=open('README.rst').read(),
    File "[...]\Python39\lib\encodings\cp1252.py", line 23, in decode
      return codecs.charmap_decode(input,self.errors,decoding_table)[0]
  UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 14840: character maps to <undefined>
  ----------------------------------------

I downloaded README.rst from 70615bc and (for me) the offending byte is now at position 15256, the last byte of the "special" closing double quotes , with utf-8 encoding \xe2\x80\x9d:

>>> with open("README.rst", "r") as f:
...     s = f.read()
...
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 15256: character maps to <undefined>
>>> with open("README.rst", "rb") as f:
...     s = f.read()
...
>>> s[15230:15270]
b'aka \xe2\x80\x9cResident Set Size\xe2\x80\x9d. \r\nIn some c'
#                            this byte here ^^^

The issue is that the default encoding for open() is not always utf-8:

>>> with open("README.rst", "r") as f:
...     print(f.encoding)
...
cp1252

Replacing long_description=open('README.rst').read() with long_description=open('README.rst', encoding='utf-8').read() in setup.py would solve this issue.

fabianp commented 2 years ago

I uploaded a new version to pypi (0.60). Can you check if it solves the issue? thanks!

sg495 commented 2 years ago

Solved by v0.60.