从python中的同一文件夹导入失败

2024-03-28 15:33:37 发布

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

我有一个文件夹:locust_runner。其中有两个文件:locust_runner.pylocust_maker.py。在locust_maker.py中,我想导入locust_runner中定义的所有内容。你知道吗

如果我这样做了:

from .locust_runner import *

没有突出显示表明这是一个错误。但是,如果我运行它,我会得到:

SystemError: Parent module '' not loaded, cannot perform relative import

我尝试了from locust_runner import locust_runner和我能想到的所有其他组合,但都没用。我怎样才能让它发挥作用?你知道吗


Tags: 文件frompyimport文件夹内容定义错误