On Tue, 2007-10-09 at 09:35 -0700, Xan wrote: > How? > > I have my django app in: > /home/xan/anadoc/analitzador/ > > and my script in: > > /home/xan/anadoc/transformacions/script.py > > My script code is: > > import os, sys > sys.path.append('/home/xan/anadoc/analitzador/') > os.environ['DJANGO_SETTINGS_MODULE'] = 'analitzador.settings' > from django.conf import settings > from analitzador.analisi.models import Centre > > print Centre.objects.all() > > > but when I run it, I get: > python prova2.py > Traceback (most recent call last): > File "prova2.py", line 5, in <module> > from analitzador.analisi.models import Centre > ImportError: No module named analitzador.analisi.models > > but if I run in /home/xan/anadoc/ (super directory of my app) all > works
Python automatically puts the current working directory into the paths it searchs (sys.path). So when you are in /home/xan/anadoc/, it gets added to the search path for imports, so "import analitzador" works. When you are in /home/xan/anadoc/transformacions/, "import analitzador" won't work unless you add /home/xan/anadoc to your python path. You have only added /home/xan/anadoc/analitzador/ to the search path, which doesn't help you here (although it does help you import things *inside* of analitzador/) Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---