Skip to content

ImportError: attempted relative import with no known parent package #55

Description

@NOTOKComputers

我下载源码后,使用python方式运行的过程出现了报错,下文中我暂时解决了它。

请确认下这是否是我使用的问题?还是说项目的确有python打包错误需要修正?

终端日志:

(.venv) aaa@aaa-con:~/workspace/tmp/ddddocr-fastapi-main$ python app/main.py
Traceback (most recent call last):
  File "/home/aaa/workspace/tmp/ddddocr-fastapi-main/app/main.py", line 5, in <module>
    from .models import OCRRequest, SlideMatchRequest, DetectionRequest, APIResponse
ImportError: attempted relative import with no known parent package
(.venv) aaa@aaa-con:~/workspace/tmp/ddddocr-fastapi-main$ vim app/main.py
(.venv) aaa@aaa-con:~/workspace/tmp/ddddocr-fastapi-main$ python app/main.py
Traceback (most recent call last):
  File "/home/aaa/workspace/tmp/ddddocr-fastapi-main/app/main.py", line 6, in <module>
    from .services import ocr_service
ImportError: attempted relative import with no known parent package

暂时修复方式:
修改app/main.py的第五行第六行

# from .models import OCRRequest, SlideMatchRequest, DetectionRequest, APIResponse
# from .services import ocr_service
from models import OCRRequest, SlideMatchRequest, DetectionRequest, APIResponse
from services import ocr_service

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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