python packaging causes importerror

Posted by Absolute0 on Stack Overflow See other posts from Stack Overflow or by Absolute0
Published on 2010-12-31T20:45:47Z Indexed on 2010/12/31 20:53 UTC
Read the original article Hit count: 287

Filed under:
|
|

I am getting an annoying import error when I try to import a variable in an init.py file. I have attached the files involved and my directory structure:

#/home/me/app/app/__init__.py
from flaskext.sqlalchemy import SQLAlchemy

db = SQLAlchemy(app)

#/home/me/app/app/models/__init__.py
from datetime import datetime
from app import db

#shell
[me@archlinux app]$ pwd
/home/me/app
[me@archlinux app]$ ./manage.py 
/home/me/app/app/__init__.pyc
Traceback (most recent call last):
  File "./manage.py", line 7, in <module>
    from app import app
  File "/home/me/app/app/__init__.py", line 3, in <module>
    from app.views.post import post
  File "/home/me/app/app/views/post.py", line 4, in <module>
    from app.models import Post
  File "/home/me/app/app/models/__init__.py", line 5, in <module>
    from app import db
ImportError: cannot import name db

[me@archlinux app]$ tree 
.
+-- apikey.txt
+-- manage.py
+-- app
¦   +-- forms
¦   ¦   +-- __init__.py
¦   ¦   +-- __init__.py~
¦   +-- __init__.py
¦   +-- __init__.py~
¦   +-- __init__.pyc
¦   +-- models
¦   ¦   +-- __init__.py
¦   ¦   +-- __init__.py~
¦   ¦   +-- __init__.pyc
¦   +-- static
¦   ¦   +-- css
¦   ¦   ¦   +-- style.css
¦   ¦   +-- images
¦   ¦   ¦   +-- favicon.png
¦   ¦   ¦   +-- logo.png
¦   ¦   ¦   +-- text_logo.png
¦   ¦   ¦   +-- thumb_down_active.png
¦   ¦   ¦   +-- thumb_down_inactive.png
¦   ¦   ¦   +-- thumb_up_active.png
¦   ¦   ¦   +-- thumb_up_inactive.png
¦   ¦   +-- js
¦   ¦   ¦   +-- index.js
¦   ¦   +-- sitemap.xml
¦   +-- templates
¦   ¦   +-- 404.html
¦   ¦   +-- 500.html
¦   ¦   +-- about.html
¦   ¦   +-- base.html
¦   ¦   +-- feedback
¦   ¦   ¦   +-- feedback_form.html
¦   ¦   +-- form.html
¦   ¦   +-- posts
¦   ¦   ¦   +-- comment.html
¦   ¦   ¦   +-- post.html
¦   ¦   ¦   +-- posts.html
¦   ¦   +-- spam.html
¦   ¦   +-- terms.html
¦   ¦   +-- users
¦   ¦       +-- login_form.html
¦   ¦       +-- sign_up_form.html
¦   +-- util
¦   ¦   +-- forms.py
¦   ¦   +-- honeypot.py
¦   ¦   +-- __init__.py
¦   ¦   +-- __init__.py~
¦   ¦   +-- json_http.py
¦   ¦   +-- models.py
¦   ¦   +-- spam.py
¦   +-- views
¦       +-- feedback.py
¦       +-- __init__.py
¦       +-- __init__.pyc
¦       +-- post.py
¦       +-- post.pyc
¦       +-- user.py
+-- settings.py
+-- settings.pyc
+-- TiddlyWiki.html

13 directories, 49 files

What might be the problem?

© Stack Overflow or respective owner

Related posts about python

Related posts about packages