3

我正在为我的 python 代码编译 Windows 安装程序。我主要编写与语言相关的工具,并在我的文档中包含需要 utf-8 字符串的示例,包括 README 文件。

我正在慢慢地从 Python 2 迁移到 Python 3,最近发现命令

python setup.py bdist_wininst

适用于 python 2 但不适用于 python 3。

我已经将问题追溯到我的自述文件中包含 unicode。自述文件被读入 setup.py。

该错误发生在 Python36\lib\distutils\command\bdist_wininst.py

错误是:UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character

在 python 2.7 中,bdist_wininst.py 中的相关代码是

    if isinstance(cfgdata, str):
        cfgdata = cfgdata.encode("mbcs")

在 python 3.6 中,bdist_wininst.py 中的等效代码是

    try:
        unicode
    except NameError:
        pass
    else:
        if isinstance(cfgdata, unicode):
            cfgdata = cfgdata.encode("mbcs")

这是我的自述文件: https ://github.com/timmahrt/pysle/blob/master/README.rst

这是我的 setup.py 文件,它读取自述文件 https://github.com/timmahrt/pysle/blob/master/setup.py

以及 setup.py 中的相关行:

long_description=codecs.open('README.rst', 'r', encoding="utf-8").read()

我的问题:在这种情况下,有没有办法让 python 3 开心?

4

0 回答 0