librelist archives

« back to archive

ImportError in nested structure

ImportError in nested structure

From:
Marian Steinbach
Date:
2013-11-07 @ 12:06
Hi!

My plan is to create two webapps which share resources among each other and
with other, non webapp-related code. I've set up a template to test the
structure. This is the file hierarchy, with "modal.py" being an example of
a resource common to all project code and webapps/util.py" being a resource
used by both web apps.

./model.py
./webapps
./webapps/__init__.py
 ./webapps/one
./webapps/one/__init__.py
./webapps/one/rundev.py
 ./webapps/one/views.py
./webapps/two
./webapps/util.py

I try to start the dev server using:

python -m webapps.one.rundev

This is what rundev.py looks like:

import webapps.one
if 'app' in dir(webapps.one):
    print "There is something called 'app' inside webapps.one."
 webapps.one.app.run(debug=True)

This is the output:

There is something called 'app' inside webapps.one.
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader
 Traceback (most recent call last):
  File
"/Users/marian/github/flask-multiapp-template/webapps/one/rundev.py", line
1, in <module>
    import webapps.one
ImportError: No module named webapps.one

This seems to be a contradiction. If the import in line one of rundev.py
would fail, there couldn't be an evaluation of dir(webapps.one).

What am I doing wrong?

The complete demo for this is available as repository on Github.
https://github.com/marians/flask-multiapp-template

Thanks for your help!

Marian

Re: ImportError in nested structure

From:
Marian Steinbach
Date:
2013-11-07 @ 13:22
Responding to myself...

Unfortunately it seems impossible to place the rundev.py script inside the
webapps module structure (for reasons I don't quite understand). I moved it
up and now it works fine.