找不到另一个子目录中保存的模块

2024-06-03 00:00:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Python文件,我正试图导入到会话中。文件结构如下所示

-object_detection
--__init__.py
--export_inference_graphy.py
--protos 
---__init__.py
---pipeline_pb2.py

从导出图文件中,我尝试导入管道pb2

但是,我得到了以下错误

from object_detection.protos import pipeline_pb2
Traceback (most recent call last):

  File "<ipython-input-60-76f12fdd6acf>", line 1, in <module>
    from object_detection.protos import pipeline_pb2

ModuleNotFoundError: No module named 'object_detection.protos'; 'object_detection' is not a package

我还尝试了以下方法,每种方法都会导致相同的错误

import sys
sys.path.append('/protos')
import pipeline_pb2

from ..protos import pipeline_pb2

Tags: 文件方法frompyimportpipelineobjectinit