ppannuto / python-titlecase

Python library to capitalize strings as specified by the New York Times Manual of Style
MIT License
254 stars 38 forks source link

Failure to install: cannot read unicode char when extracting version #78

Closed cr-perry closed 3 years ago

cr-perry commented 3 years ago

I'm getting this error when pip-installing the library under python 3.7:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-n2291b7g/titlecase/setup.py", line 21, in <module>
        version=read_version('titlecase/__init__.py'),
      File "/tmp/pip-install-n2291b7g/titlecase/setup.py", line 13, in read_version
        for line in read_file(rel_path).splitlines():
      File "/tmp/pip-install-n2291b7g/titlecase/setup.py", line 10, in read_file
        return f.read()
      File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 521: ordinal not in range(128)

Looking at the code at setup.py, it appears that read_version() uses read_file() to read titlecase/__init__.py. However this init file is utf-8 encoded, and thus the open() call (that uses text mode by default) fails to decode as ascii is assumed.

This appears to have been introduced in the latest release, as it was working (for us) flawlessly before.

Thanks! Yonatan

Gateswong commented 3 years ago

I got similar problem. #80 might help

ppannuto commented 3 years ago

I just pushed v2.1, which incorporates some setup fixes. If something's still broken for your setup, happy to take a PR to fix.