Can Import Absolute Path, but Relative Path Does Not Work

Viewed 18

I have a folder path as follows:

python/
    intro/
        project3/
            menu/
                MenuOptions.py
                __init__.py
            util/
                Parser.py
                __init__.py
            __init__.py
        __init__.py
    __init__.py
__init__.py

I am attempting to use a relative path to import Parser.py into MenuOptions.py:

from ..util import Parser

This gives me an error, ImportError: attempted relative import with no known parent package

However, both of the following will work:

from python.intro.project3.util import Parser
from util import Parser

For the purpose of this task, I must use the relative path. Why does the relative path not work?

0 Answers
Related