ValueError:尝试在导入时超出顶级包的相对导入

时间:2019-05-09 00:39:13

标签: python python-3.x

我有这样的结构:

.
├── __init__.py
├── folder1
│   ├── __init__.py
│   └── file_will_import.py
└── folder2
  ├── __init__.py
  └── helper.py

file_will_import.py 包含以下内容:

from ..folder2 import helper
helper.h1()

helper 上。 py 具有此功能:

def h1():
    print("Hello")

当我跑步时 python file_will_import py ,它会给出以下错误:

Traceback (most recent call last):
  File "file_will_import.py", line 1, in <module>
    from ..folder2 import helper
ValueError: attempted relative import beyond top-level package.

我已经尝试过Google的所有功能,但似乎无济于事。

0 个答案:

没有答案
相关问题