Accessing Flask wsgi structured app from interpreter
Question: I have a Flask app structured for deployment as wsgi. An issue I have is when
I want to load files from the Python interpreter.

The structure is:

    
    
    |----api
    |---------api
    |--------------static
    |--------------templates
    |--------------venv
    |--------------models.py
    |--------------...
    

So that in the Python interpreter, when I load files in the directory
`api/api` I need to access them as `dir.filename`. For example, if I have a
file, `api/api/models.py`, I can load it by entering the command `from
api.mb_models import db`... however, this syntax chokes when I run the wsgi
app via a web server. I then get an error that the file does not exits:

`Traceback (most recent call last): File "api/extract.py", line 15, in
<module> import api.models as models ImportError: No module named api.models`

I also tried set the os variable as follows,

    
    
    path = 'api'
    os.chdir(path)
    

and while this works now as wsgi, I got the same error when trying to load
from the interpreter. The only way I can get this to currently run as wsgi is
without specifying the path in my import statements or using the os attribute,
which does not work when I load the files in the interpreter

The question is how to share the same configuration for deployment as a wsgi
app AND for running from the Python interpreter.

Note: I am using a virtual environment.

**EDIT**

I removed all references of `dir` in my file imports, so the wsgi app is
functioning as desired, then ran `os.cwd()` in the interpreter, which gave me
the expected result of `/Users/gms/development/python/api`. I then set the
working directory using `os.chdir('/Users/gms/development/python/api/api')`,
ran `os.cwd()` and got the desired result for the working directory, but I
still get a `ImportError: No module named extract` when I try loading it from
the interpreter.


Answer: I figured it out. I need to set these in the interpreter:

    
    
    import sys
    sys.path.append('working path here')
    

And, voila, everything works as desired.

