Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 1
    How are you running the script? Are you running python sub_dir/module_sub_dir.py? Commented Apr 19, 2022 at 18:05
  • 1
    Starting python 2.5 you can import from parent using three dots: from ... import module_dir Commented Apr 19, 2022 at 18:05
  • @mikicz I have opened 'dir' folder (main/root folder) in VS code. Commented Apr 19, 2022 at 18:07
  • @PietroD'Antuono got error ImportError: attempted relative import with no known parent package Commented Apr 19, 2022 at 18:08
  • 1
    If you have dir folder open, then you shall import directly from the current folder. Then it is: from . import module_dir. Also, the folder containing module_dir.py must contain an __init__.py as well to be "recognized" as a python package Commented Apr 19, 2022 at 18:10