problems importing an app

3 views
Skip to first unread message

Yuri

unread,
Dec 28, 2005, 2:29:24 PM12/28/05
to Django users
I am trying to get the basic tutorial examples working but keep running
into a problem importing the app. After I create the polls app as
suggested in the tutorial
(http://www.djangoproject.com/documentation/tutorial1/), put the sample
code into polls/models/polls.py and add 'myproject.apps.polls' to
myprojects/settings.py, I try to run

django-admin.py sql polls

which gives me the following error message:

Traceback (most recent call last):
File "/usr/bin/django-admin.py", line 5, in ?
pkg_resources.run_script('Django==0.90', 'django-admin.py')
...
File
"/usr/lib/python2.4/site-packages/Django-0.90-py2.4.egg/django/utils/translation.py",
line 164, in _fetch
app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]),
appname[p+1:])
AttributeError: 'module' object has no attribute 'polls'

(Full stack trace at the end of the message)

I get the exact same error message if I just go into the python console
and try to import the models manually with "from django.models.polls
import polls, choices"

My project directory is symlinked into
/usr/lib/python2.4/site-packages/ and I can import the project settings
with "import myproject.settings" The database is set up (using mysql)
and seems to have gotten initialized correctly. I've tried with both
python 2.3 and 2.4 and I get the same result.

I have a copy of all the files I am using in
http://www.freewisdom.org/tmp/django/ (though, all of them are straight
out of the tutorial).

Any suggestions?

- yuri

The full stack trace:

Traceback (most recent call last):
File "/usr/bin/django-admin.py", line 5, in ?
pkg_resources.run_script('Django==0.90', 'django-admin.py')
File
"/usr/lib/python2.4/site-packages/setuptools-0.6a7-py2.4.egg/pkg_resources.py",
line 407, in run_script
self.require(requires)[0].run_script(script_name, ns)
File
"/usr/lib/python2.4/site-packages/setuptools-0.6a7-py2.4.egg/pkg_resources.py",
line 920, in run_script
execfile(script_filename, namespace, namespace)
File
"/usr/lib/python2.4/site-packages/Django-0.90-py2.4.egg/EGG-INFO/scripts/django-admin.py",
line 139, in ?
main()
File
"/usr/lib/python2.4/site-packages/Django-0.90-py2.4.egg/EGG-INFO/scripts/django-admin.py",
line 81, in main
translation.activate('en-us')
File
"/usr/lib/python2.4/site-packages/Django-0.90-py2.4.egg/django/utils/translation.py",
line 192, in activate
_active[currentThread()] = translation(language)
File
"/usr/lib/python2.4/site-packages/Django-0.90-py2.4.egg/django/utils/translation.py",
line 181, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File
"/usr/lib/python2.4/site-packages/Django-0.90-py2.4.egg/django/utils/translation.py",
line 164, in _fetch
app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]),
appname[p+1:])
AttributeError: 'module' object has no attribute 'polls'

Adrian Holovaty

unread,
Dec 28, 2005, 3:38:25 PM12/28/05
to django...@googlegroups.com
On 12/28/05, Yuri <qara...@gmail.com> wrote:
> I am trying to get the basic tutorial examples working but keep running
> into a problem importing the app. After I create the polls app as
> suggested in the tutorial
> (http://www.djangoproject.com/documentation/tutorial1/), put the sample
> code into polls/models/polls.py and add 'myproject.apps.polls' to
> myprojects/settings.py, I try to run
>
> django-admin.py sql polls
>
> which gives me the following error message:

Hey Yuri,

Move the "polls" directory into "myproject/apps", and give it another
shot. You're trying to import myproject.apps.polls, but that directory
doesn't exist. Good luck!

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Yuri T.

unread,
Dec 28, 2005, 8:03:47 PM12/28/05
to django...@googlegroups.com
Yes, this took care of it. Thanks.

I guess I should have read the documentation more carefully, since it
does say I needed to cd to myproject/apps before creating an app.
Just as a suggestion, however, it might be useful to mark visually
more clearly in the text the actual steps that the user need to do.
The tutorial has a lot of detailed background information, which is
very useful, but it is easy to miss a step among them. One possibily
is to include trivial commands like "cd" in green code blocks, saying

cd myproject/apps

in addition to "change into the myproject/apps directory", not because
the readers are not going to figure out how to change the directory
but because this could make it possible to use the green code blocks
as a check list of things you needed to have done by now.

Another possibility to consider is adding error messages for import
cases. Django seems to do a lot of magic with importing, which makes
hard for the user to figure out where exactly it expects to actually
find the modules. Perhaps it would help if the code that did the
importing magic printed a message saying what exactly it was looking
for ("myproject.apps.polls" in this case).

But that's all details - it's a great framework and a great tutorial.

- yuri

Adrian Holovaty

unread,
Dec 29, 2005, 10:21:16 AM12/29/05
to django...@googlegroups.com
On 12/28/05, Yuri T. <qara...@gmail.com> wrote:
> Another possibility to consider is adding error messages for import
> cases. Django seems to do a lot of magic with importing, which makes
> hard for the user to figure out where exactly it expects to actually
> find the modules. Perhaps it would help if the code that did the
> importing magic printed a message saying what exactly it was looking
> for ("myproject.apps.polls" in this case).

Hi Yuri,

The magic with importing is going away in the magic-removal branch,
which we're currently working on and should be integrated into Django
proper within a couple of weeks. For more information, see
http://code.djangoproject.com/wiki/RemovingTheMagic .

Reply all
Reply to author
Forward
0 new messages