pip3 install xpinyin hanzi = '小明' p = Pinyin() pinyin = p.get_pinyin(hanzi,'') print(pinyin) ''''''' xiaoming '''''''