How to resolve “ValueError: attempted relative import beyond top-level package”
问题 I have the following problem with my project, help me please! Here is the structure of my package: /pkg /pkg/__init__.py /pkg/sub1/__init__.py /pkg/sub2/__init__.py /pkg/sub1/foo1.py /pkg/sub2/foo2.py Here is implementation of foo1.py: from ..sub2 import foo2 def f(): print("Hello!") When I run foo1 I get error: ValueError: attempted relative import beyond top-level package . I can solve it doing the following adjustment: import sys import os sys.path.append(os.path.abspath(os.path.pardir))