Skip to content

受rapidocr影响,cnstd在被cnocr启动时产生报错 #104

Description

@fred913

错误日志如下

Traceback (most recent call last):
  File "C:\Users\sheng.fan\Projects\meituan-screenshot\main.py", line 339, in <module>
    results = extract_menu_items(image_fp)
  File "C:\Users\sheng.fan\Projects\meituan-screenshot\main.py", line 278, in extract_menu_items
    ocr = CnOcr()
  File "C:\Users\sheng.fan\Projects\meituan-screenshot\.venv\Lib\site-packages\cnocr\cn_ocr.py", line 170, in __init__
    self.det_model = CnStd(
                     ~~~~~^
        det_model_name,
        ^^^^^^^^^^^^^^^
    ...<4 lines>...
        **det_more_configs,
        ^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\sheng.fan\Projects\meituan-screenshot\.venv\Lib\site-packages\cnstd\cn_std.py", line 99, in __init__
    self.det_model = det_cls(
                     ~~~~~~~^
        model_name=model_name,
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
        **kwargs,
        ^^^^^^^^^
    )
    ^
  File "C:\Users\sheng.fan\Projects\meituan-screenshot\.venv\Lib\site-packages\cnstd\ppocr\rapid_detector.py", line 169, in __init__
    self._detector = TextDetector(config)
                     ~~~~~~~~~~~~^^^^^^^^
  File "C:\Users\sheng.fan\Projects\meituan-screenshot\.venv\Lib\site-packages\rapidocr\ch_ppocr_det\main.py", line 47, in __init__
    self.session = get_engine(cfg.engine_type)(cfg)
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "C:\Users\sheng.fan\Projects\meituan-screenshot\.venv\Lib\site-packages\rapidocr\inference_engine\onnxruntime\main.py", line 20, in __init__
    model_root_dir = Path(cfg.get("model_root_dir"))
  File "C:\Users\sheng.fan\AppData\Roaming\uv\python\cpython-3.13-windows-x86_64-none\Lib\pathlib\_local.py", line 503, in __init__
    super().__init__(*args)
    ~~~~~~~~~~~~~~~~^^^^^^^
  File "C:\Users\sheng.fan\AppData\Roaming\uv\python\cpython-3.13-windows-x86_64-none\Lib\pathlib\_local.py", line 132, in __init__
    raise TypeError(
    ...<2 lines>...
        f"not {type(path).__name__!r}")
TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'NoneType'

解决方法是删除3.8.1(最新版)rapidocr,换用3.6.0(pip install rapidocr==3.6.0)即可使用。观察日志和代码,推断是rapidocr新增配置项model_root_dir,而CnOCR/CnSTD未更新提供导致的,也许可以将这些依赖版本pin一下。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions