【发布时间】:2018-09-14 16:32:27
【问题描述】:
我有以下python包结构:
rkstr8/cloud/batch.py
rkstr8/profiling/test.py
我正在尝试将一个名为 BatchJobListStatusPoller 的类从 batch.py 导入 test.py,但是当我在 test.py 中运行此导入语句时,它给了我错误:ModuleNotFoundError: No module named 'rkstr8':
from rkstr8.cloud.batch import BatchJobListStatusPoller
rkstr8/ 文件夹,以及 cloud/ 和 profiling/ 子文件夹都有一个__init__.py。
我在这里做错了什么?
【问题讨论】:
-
rkstr8 是您项目的父文件夹吗?
-
不,真正的父文件夹是
aws-sfn-tutorial-->aws-sfn-tutorial/rkstr8/.... -
您为启动程序而运行的第一个文件在哪里?就像你做
python whatever.py -
我运行
python test.py,在aws-sfn-tutorial/rkstr8/profiling/中 -
是的,我的回答中提到了这个问题。这实际上是不可能的,因为 Python 仅搜索启动程序的目录/子目录以进行导入。我会用你可能的解决方案更新我的答案。
标签: python import module package