Py3: Import relative path module

Gnarlodious gnarlodious at gmail.com
Mon Nov 1 11:30:34 EDT 2010


On Nov 1, 5:36 am, Peter Otten wrote:

> Remove the directory containing the importing file from your sys.path.
I removed all sys.path customizations and rebooted.

In the following scenario, I am programming in one.py attempting to
import Data.py which is in the alpha folder:
> $ tree
> .
> `-- alpha
>     |-- __init__.py
>     |-- beta
>     |   |-- __init__.py
>     |   `-- one.py
>     `-- gamma
>         |-- __init__.py
>         `-- two.py

However, all I can get is error:

    from .. import Data
ValueError: Attempted relative import in non-package

Why is the parent folder not recognized as a package? Because right
now I am liberally using sys.path, which works but is a little too
messy.

-- Gnarlie



More information about the Python-list mailing list