I'm compiling windows installers for my python code. I mostly write language-related tools and include examples that require utf-8 strings in my documentation, including the README file.
I'm slowly moving from Python 2 to Python 3 and recently found that the command
python setup.py bdist_wininst
works fine with python 2 but not for python 3.
I've traced the problem to the inclusion of unicode in my readme file. The readme file gets read into setup.py.
The bug occurs in Python36\lib\distutils\command\bdist_wininst.py
The error is: UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character
In python 2.7 the relevant code in bdist_wininst.py is
if isinstance(cfgdata, str):
cfgdata = cfgdata.encode("mbcs")
In python 3.6 the equivalent code in bdist_wininst.py is
try:
unicode
except NameError:
pass
else:
if isinstance(cfgdata, unicode):
cfgdata = cfgdata.encode("mbcs")
Here is my readme file: https://github.com/timmahrt/pysle/blob/master/README.rst
And here is my setup.py file that reads in the README file https://github.com/timmahrt/pysle/blob/master/setup.py
And the relevant line from setup.py:
long_description=codecs.open('README.rst', 'r', encoding="utf-8").read()
My question: Is there a way to make python 3 happy in this case?