{"id":7093,"library":"cn2an","title":"Chinese/Arabic Numeral Converter (cn2an)","description":"cn2an is a Python toolkit for quickly converting between Chinese numerals and Arabic numerals. It supports conversion of standard Chinese numbers, large-form Chinese numbers, mixed Chinese and Arabic numbers, and provides features for sentence-level conversion, including dates, fractions, percentages, and temperatures. The library is actively maintained, with the latest version being 0.5.23, and targets Python 3.6+ for local installation.","status":"active","version":"0.5.23","language":"en","source_language":"en","source_url":"https://github.com/Ailln/cn2an","tags":["nlp","chinese","numerals","conversion","arabic","utility"],"install":[{"cmd":"pip install cn2an -U","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required Python version for local installation.","package":"Python","version":">=3.6"}],"imports":[{"symbol":"cn2an","correct":"import cn2an"}],"quickstart":{"code":"import cn2an\n\n# Chinese to Arabic conversion (strict mode is default)\narabic_num = cn2an.cn2an(\"一百二十三\")\nprint(f\"'一百二十三' -> {arabic_num}\")\n\n# Arabic to Chinese conversion (low mode is default)\nchinese_num = cn2an.an2cn(\"12345\")\nprint(f\"'12345' -> {chinese_num}\")\n\n# Sentence transformation (experimental)\nsentence = cn2an.transform(\"小王捡了一百块钱\")\nprint(f\"'小王捡了一百块钱' -> {sentence}\")","lang":"python","description":"Demonstrates basic conversion from Chinese to Arabic and Arabic to Chinese numerals, along with sentence-level transformation. Various modes (`strict`, `normal`, `smart` for cn2an; `low`, `up`, `rmb` for an2cn) are available to handle different input formats."},"warnings":[{"fix":"Ensure your environment uses Python 3.6 or newer. Upgrade your Python interpreter if necessary.","message":"Older versions of cn2an (e.g., v0.1.0) claimed Python 2.7 support. Current versions (0.3.3 onwards) explicitly require Python 3.6 or higher. Attempting to install or use on Python 2.x will result in an error.","severity":"breaking","affected_versions":"<0.3.3 supported Python 2.x, >=0.3.3 requires Python 3.6+"},{"fix":"For critical applications, carefully test `transform()` with your specific sentence patterns. Consider using `cn2an.cn2an()` or `cn2an.an2cn()` on extracted number phrases for more predictable results.","message":"The `cn2an.transform()` method is considered experimental and might produce unexpected or inaccurate conversions for complex sentences.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the documentation for available modes and their specific behaviors. Explicitly pass the desired `mode` argument to the conversion functions (e.g., `cn2an.cn2an('一二三', 'normal')`) to ensure correct parsing.","message":"Both `cn2an.cn2an()` and `cn2an.an2cn()` functions accept a `mode` parameter (e.g., 'strict', 'normal', 'smart' for Chinese to Arabic; 'low', 'up', 'rmb' for Arabic to Chinese). Not understanding or specifying the correct mode for your input can lead to incorrect or unexpected conversion results.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install cn2an`","cause":"The cn2an library is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'cn2an'"},{"fix":"Manually update `PyYAML` first, ignoring installed versions, then install `cn2an`: `pip install PyYAML -U --ignore-installed`","cause":"This error occurs during installation (often when PyYAML is a dependency being updated) due to a conflict with an older `distutils` installation of `PyYAML`.","error":"ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall."},{"fix":"Review the API documentation for `cn2an.cn2an()` or `cn2an.an2cn()` to ensure you are using one of the valid mode strings (e.g., 'strict', 'normal', 'smart' for Chinese to Arabic conversion). For example: `cn2an.cn2an('一百二十三', 'strict')`.","cause":"An invalid or unsupported mode string was provided to `cn2an.cn2an()` (or similar for `cn2an.an2cn()`).","error":"ValueError: Mode value error, only ['strict', 'normal', 'smart'] are supported!"}]}