Python Relative import does not work from command line gives ValueError
Question: My Directory structure is as follows

    
    
    microblog/__init__.py
             urls.py
             views.py
             wsgi.py
             settings/__init__.py
                     testing.py
                     base.py
                     local.py
    

In testing.py I have a relative import

    
    
    from .base import *
    ...
    ...more code
    

When I try to run the testing.py from the command line in the directory
microblog/settings using python testing.py

    
    
    from .base import *
    ValueError: Attempted relative import in non-package
    

Why does this not work. The settings directory is a valid package with a
**init**.py . I do not get the ValueError from the command line only If I
change the

    
    
    from .base import *
    

to

    
    
    from base import *
    

I am trying to understand why the relative local import fails and gives a
ValueError when I run the "testing.py" package with a relative import in it
from the command line.


Answer: The answer from icyrock in [this
post](http://stackoverflow.com/questions/9123062/python-relative-import-
example-code-does-not-work?lq=1) clarifies exactly what I didnt understand
about the python "repl".

In the Directory microblog/settings when I run

    
    
    python testing.py
    

It actually puts testing in the package "main" and it does not know that
testing is part of the package "settings". Instead running "testing.py" as a
module as part of its normal package hierarchy using this

    
    
    python -m microblog.settings.testing 
    

Runs it without any ValueError since now python knows that "testing" is part
of package "settings" where the relative local import "from .base import *"
makes perfect sense.

