python: how to import nested package?
Question: I have a package named myscrapy, the directory structure is:

    
    
    + spider-common
    --+ myscrapy
    ----+ basespiders
    ------+ __init__.py
    ------+ mod.py
    --+ __init__.py
    --+ mod.py
    

And I have an enviroment variable:

    
    
    export PYTHONPATH=~/spider-common
    

This is success:

    
    
    from myscrapy import mod
    

But it failed:

    
    
    from myscrapy.basespiders import mod
    

ImportError: No module named myscrapy.basespiders

why?


Answer: The import command treads every folder only as a package (which is
importable), when a certain structure is present (see [Python
Docs](http://docs.python.org/2/tutorial/modules.html#packages)). You have to
place a `__init__.py` file (could be a blank one) in every subdirectory you
import.

