zhconv
raw JSON → 1.4.3 verified Fri May 01 auth: no python
A simple implementation of Simplified-Traditional Chinese conversion. Supports zh-Hans, zh-Hant, and regional variants like zh-tw, zh-cn, etc. Based on MediaWiki conversion tables. Current version: 1.4.3. Release cadence is low; maintained as needed.
pip install zhconv Common errors
error ImportError: cannot import name 'convert' from 'zhconv' ↓
cause Using import zhconv and then zhconv.convert, but the function is not a module-level attribute when imported as a module.
fix
Use 'from zhconv import convert' instead of 'import zhconv'.
error TypeError: convert() missing 1 required positional argument: 'target' ↓
cause Calling convert() without providing the target variant string.
fix
Provide target variant: convert('text', 'zh-tw')
Warnings
gotcha The library does not auto-detect the source variant; you must specify the target variant. If you want to detect the source, use other libraries like opencc or langid. ↓
fix Always specify target variant explicitly, e.g., 'zh-cn' when converting to simplified Chinese.
gotcha Conversion is one-way per call; to convert 'back' you need to call convert again with the opposite target. The library does not maintain state. ↓
fix Call convert(text, 'zh-cn') then convert(result, 'zh-tw') for bidirectional conversion.
Imports
- convert wrong
import zhconvcorrectfrom zhconv import convert
Quickstart
from zhconv import convert
# Convert simplified Chinese to traditional
result = convert('我爱编程', 'zh-tw')
print(result) # 我愛編程
# Convert traditional to simplified
result2 = convert('我愛編程', 'zh-cn')
print(result2) # 我爱编程