0

With this directory structure (this is a toy example, for brevity):

enter image description here

I have these simple modules:

Main module

One.py

Two.py

When I try to run m.py, I get an error like

File "...\test\p2\two.py", line 1, in from ..p1 import one ImportError: attempted relative import beyond top-level package

What is the correct way to (relative) import module one into module two, when module one is in a package (p1) at the same level in the directory hierarchy as the package (p2) containing module two? I tried "from ..p1" since p1 is at the same dir level as p2, so "up 2 levels, down 1" fit my brain at first. I also tried "from .p1" and "from test.p1" but no joy.

user1443098
  • 6,487
  • 5
  • 38
  • 67

0 Answers0