Этот файл я запускаю из отдельного окна баш (не в среде джанго)
test.py
#!/usr/bin/env python
import sys
print sys.path
from models import Book
count = Book.objects.all()
print count
$ export DJANGO_SETTINGS_MODULE=myproject.settings
$ export PYTHONPATH=/home/r/PROJECTS/django/tmp/myproject
$ chmod +x test.py
$ ./test.py
r@krv:~/PROJECTS/django/tmp/myproject$ ./test.py
['/home/r/PROJECTS/django/tmp/myproject', '/home/r/PROJECTS/django/tmp/myproject', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/Numeric', '/usr/lib/python2.5/site-packages/PIL', '/usr/lib/python2.5/site-packages/gst-0.10', '/var/lib/python-support/python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0', '/var/lib/python-support/python2.5/gtk-2.0', '/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode']
Traceback (most recent call last):
File "./test.py", line 7, in <module>
from apps.models import Book
File "/home/r/PROJECTS/django/tmp/myproject/apps/models.py", line 5, in <module>
from django.db import models
File "/usr/lib/python2.5/site-packages/django/db/__init__.py", line 10, in <module>
if not settings.DATABASE_ENGINE:
File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 269, in __getattr__
self._setup()
File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 40, in _setup
self._wrapped = Settings(settings_module)
File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 75, in __init__
raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'myproject.settings' (Is it on sys.path? Does it have syntax errors?): No module named myproject.settings
r@krv:~/PROJECTS/django/tmp/myproject$
Где может быть ошибка?
Спасибо