python anacode 安装opencc进行繁简转换

1,进入到anacode的目录,比如我是win系统,在win系统下,anacode的目录一般是系统盘(比如c盘)的,programdata文件夹,然后执行opencc安装命令

pip3 install opencc-python-reimplemented

由于网络原因,大家都懂的,有时候会出现这样的错误,比如:

ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.

这个没关系,多试几次,总会通的

2,安装完成后,直接引入使用

from opencc import OpenCC

text = '楓葉'
jianti_text = OpenCC('t2s').convert(text)
print(jianti_text) #枫叶




t2s 是繁体变简体,s2t是简体变繁体

 

  • t2s - Traditional Chinese to Simplified Chinese   繁体转为简体
  • s2t - Simplified Chinese to Traditional Chinese   简体转为繁体
  • mix2t - Mixed to Traditional Chinese  
  • mix2s - Mixed to Simplified Chinese

你可能感兴趣的:(python,python)