question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Could not install on Windows 7 x64 - setup.py fails because of UTF-8 encoding of README.rst

See original GitHub issue

Hello, I’ve had a curious issue with the readchar module. My post also includes a workaround.

I’ve been trying to use readchar lately because I jump between Linux and Windows a lot. Last month I discovered how great python is. Since then, I’m writing various helper scripts for both platforms, and I wrote a simple question/answer function that takes y/n in one keystroke to help me with some otherwise tedious tasks.

On linux (python 3) readchar installed and runs without any problems. However, on Windows 7 64bit (tested both Python 3.4 and 3.3 because I read somewhere that readchar has issues on windows with py3.4) I cannot even install it using pip. Also, when I cloned and tried to build using simple: python-readchar (master) $ python setup.py build I get:

Traceback (most recent call last):
  File "setup.py", line 39, in <module>
    long_description=read_description(),
  File "setup.py", line 11, in read_description
    return fd.read()
  File "c:\Programs\Python34\lib\encodings\cp1250.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 2590: character maps to <undefined>

so… I investigated, and noticed that README.rst is encoded in UTF-8. I converted it to ANSI with Notepad++. The “guilty” characters were just the two characters in your name (Á and í). After that, both setup.py build and setup.py install worked. However, still, when I run readchar.readchar(), I get this strange error

  File "d:\Projects\python\mbdev.py", line 29, in ask
    answer = readchar.readchar().decode("utf-8").lower()
  File "C:\Programs\Python34\lib\site-packages\readchar-1.1.1-py3.4.egg\readchar\readchar_windows.py", line 14, in readchar
    while ch in '\x00\xe0':
TypeError: 'in <string>' requires string as left operand, not bytes

So… I changed the line 14 in readchar_windows.py from while ch in '\x00\xe0': to while ch.decode() in '\x00\xe0':

and changed my code from answer = readchar.readchar().decode("utf-8").lower() to answer = readchar.readchar().lower() And now it works on Windows. I feel that this solution might not be the optimal one, maybe on some other Windows systems the decode() is not needed as the char is already of type str. Maybe something along the lines of the type check present in readchar_linux.py is needed?

Also, I noticed that the readchar.readchar() in 1.1.0 (from pypi) returns bytes on linux, while 1.1.1 (current master from github) returns str. So, after I changed my code it stopped working on linux. After that I cloned and built rearchar from github also on my linux machine.

And now it really works on both platforms! 😃

I’m willing to do some more testing on windows in the future. @magmax Please let me know if I can help with improving and/or testing readchar_windows.py as it looks like the windows code lags behind the readchar_linux.py.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ag-eitiltcommented, Oct 3, 2016

A simpler, though less elegant (which shouldn’t take priority over working code) solution would be to stick to ASCII characters in the README: the only change necessary would be “Miguel Ángel García” -> “Miguel A’ngel Garci’a” or something similar.

EDIT: Apparently my instructor is familiar with this, and offered an even better solution: change line 10 from with open('README.rst') as fd: to with open('README.rst', encoding="utf8") as fd:

EDIT 2: I’ve opened #19 to provide my solution, as well as one for another line that needed fixing.

0reactions
mbdevplcommented, Jan 29, 2020

As #27 has been resolved, I think this should be closed. If anyone else experiences the same issue with the latest version (as of now: 2.0.1), please reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setuptools 5.4.1
If that encoding was a "fallback" because Python could not figure it out from the environment or OS, encoding remains unresolved. 3. If...
Read more >
Changelog - pip documentation v22.3.1
When this field is present for a release link, pip will ignore the download when installing to a Python version that doesn't satisfy...
Read more >
'charmap' codec can't decode byte 0x9d in position X ...
The problem is caused during the setup process when reading README.txt . In Windows, the default encoding is cp1252, but that readme file...
Read more >
R for Windows FAQ
An installation takes up to 175MB of disk space. We tried to make R to work with space in file names, but building...
Read more >
4. Using Python on Windows — Python 3.11.1 documentation
4.1.3. Installing Without UI¶. All of the options available in the installer UI can also be specified from the command line, allowing scripted...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found