小编Mar*_*nas的帖子

在setup.py中使用Unicode元数据的正确方法是什么?

我正在使用setuptools为Python包编写setup.py,并希望在long_description字段中包含非ASCII字符:

#!/usr/bin/env python
from setuptools import setup
setup(...
      long_description=u"...", # in real code this value is read from a text file
      ...)
Run Code Online (Sandbox Code Playgroud)

不幸的是,将unicode对象传递给setup()会使用UnicodeEncodeError中断以下两个命令之一

python setup.py --long-description | rst2html
python setup.py upload

如果我在long_description字段中使用原始UTF-8字符串,则以下命令会破坏UnicodeDecodeError:

python setup.py register

我通常通过运行'python setup.py sdist register upload'来发布软件,这意味着看到sys.argv并传递正确的对象类型的丑陋黑客就出来了.

最后,我放弃并实施了一个不同的丑陋黑客:

class UltraMagicString(object):
    # Catch-22:
    # - if I return Unicode, python setup.py --long-description as well
    #   as python setup.py upload fail with a UnicodeEncodeError
    # - if I return UTF-8 string, python setup.py sdist register
    #   fails with an …
Run Code Online (Sandbox Code Playgroud)

python unicode setuptools

9
推荐指数
1
解决办法
1792
查看次数

标签 统计

python ×1

setuptools ×1

unicode ×1