Re: cannot import name settings - accessing Django environment from external script
This is mhy laptop so I'm not bothered about where the code is stored. If it goes live it'll be correctly located/secured etc. Thanks On Dec 1, 5:03 pm, Skylar Saveland wrote: > I thought that it was best practice to not put python code in /var/www > and to own the code with an unprivileged user. Doesn't seem like it > is necessarily germane to the present topic but perhaps something to > think about. > > Am I wrong? Are there exceptions? I think I have seen some high > profile websites running application code under /var/www > > Stodge wrote: > > This: > > > sys.path.append("/var/www/sites/indigo/") > > os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' > > from django.core.management import setup_environ > > import settings > > project_directory = setup_environ(settings) > > from indigo.project.ticket.models import Ticket > > > Gives me "ImportError: No module named project.ticket.models". Hmmm. > > So it can import the settings before calling setup_environ but the > > environment isn't unusable afterwards. > > > On Dec 1, 12:51 pm, Stodge wrote: > > > Argh! Taking this a step further - I'm now trying to access my Django > > > environment from within a Trac (http://trac.edgewall.org) plugin, but > > > I'm getting a similar issue. > > > > This works: > > > > sys.path.append("/var/www/sites/indigo/") > > > os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' > > > from django.core.management import setup_environ > > > import settings > > > project_directory = setup_environ(settings) > > > > But this: > > > > sys.path.append("/var/www/sites/indigo/") > > > os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' > > > from django.core.management import setup_environ > > > import settings > > > project_directory = setup_environ(settings) > > > from django.contrib.auth.models import User > > > > Gives "ImportError: Could not import settings 'indigo.settings' (Is it > > > on sys.path? Does it have syntax errors?): No module named settings" > > > > It's the exact same code that works in my Mercurial plugin. Any ideas? > > > Thanks > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
I thought that it was best practice to not put python code in /var/www and to own the code with an unprivileged user. Doesn't seem like it is necessarily germane to the present topic but perhaps something to think about. Am I wrong? Are there exceptions? I think I have seen some high profile websites running application code under /var/www Stodge wrote: > This: > > sys.path.append("/var/www/sites/indigo/") > os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' > from django.core.management import setup_environ > import settings > project_directory = setup_environ(settings) > from indigo.project.ticket.models import Ticket > > Gives me "ImportError: No module named project.ticket.models". Hmmm. > So it can import the settings before calling setup_environ but the > environment isn't unusable afterwards. > > > On Dec 1, 12:51 pm, Stodge wrote: > > Argh! Taking this a step further - I'm now trying to access my Django > > environment from within a Trac (http://trac.edgewall.org) plugin, but > > I'm getting a similar issue. > > > > This works: > > > > sys.path.append("/var/www/sites/indigo/") > > os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' > > from django.core.management import setup_environ > > import settings > > project_directory = setup_environ(settings) > > > > But this: > > > > sys.path.append("/var/www/sites/indigo/") > > os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' > > from django.core.management import setup_environ > > import settings > > project_directory = setup_environ(settings) > > from django.contrib.auth.models import User > > > > Gives "ImportError: Could not import settings 'indigo.settings' (Is it > > on sys.path? Does it have syntax errors?): No module named settings" > > > > It's the exact same code that works in my Mercurial plugin. Any ideas? > > Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
This: sys.path.append("/var/www/sites/indigo/") os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' from django.core.management import setup_environ import settings project_directory = setup_environ(settings) from indigo.project.ticket.models import Ticket Gives me "ImportError: No module named project.ticket.models". Hmmm. So it can import the settings before calling setup_environ but the environment isn't unusable afterwards. On Dec 1, 12:51 pm, Stodge wrote: > Argh! Taking this a step further - I'm now trying to access my Django > environment from within a Trac (http://trac.edgewall.org) plugin, but > I'm getting a similar issue. > > This works: > > sys.path.append("/var/www/sites/indigo/") > os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' > from django.core.management import setup_environ > import settings > project_directory = setup_environ(settings) > > But this: > > sys.path.append("/var/www/sites/indigo/") > os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' > from django.core.management import setup_environ > import settings > project_directory = setup_environ(settings) > from django.contrib.auth.models import User > > Gives "ImportError: Could not import settings 'indigo.settings' (Is it > on sys.path? Does it have syntax errors?): No module named settings" > > It's the exact same code that works in my Mercurial plugin. Any ideas? > Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
Argh! Taking this a step further - I'm now trying to access my Django environment from within a Trac (http://trac.edgewall.org) plugin, but I'm getting a similar issue. This works: sys.path.append("/var/www/sites/indigo/") os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' from django.core.management import setup_environ import settings project_directory = setup_environ(settings) But this: sys.path.append("/var/www/sites/indigo/") os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings' from django.core.management import setup_environ import settings project_directory = setup_environ(settings) from django.contrib.auth.models import User Gives "ImportError: Could not import settings 'indigo.settings' (Is it on sys.path? Does it have syntax errors?): No module named settings" It's the exact same code that works in my Mercurial plugin. Any ideas? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
Hah.. wow. I'm glad you figured that out. I haven't used pth files in any serious manner before, so I totally wasn't thinking about that. Best of luck to you! On Nov 25, 1:08 pm, Stodge wrote: > What do you know - it's my .pth file. My Mercurial hook is in /home/ > mike/hooks and I have a path file /usr/lib64/python2.5/site-packages/ > hooks.pth defined, which contains: > > /home/mike/hooks > > If I comment this line out, I can do ./manage.py shell. If I uncomment > this line, manage.py doesn't work > > Thanks for your help. > > On Nov 25, 3:04 pm, Stodge wrote: > > > > > I can successfully start python and import the settings file. My > > settings file only imports os. > > > On Nov 25, 3:01 pm, Tim Valenta wrote: > > > > Well, does it have errors? If you navigate to the directory where > > > it's kept, can you enter the python shell and do "import settings"? > > > Given all of the trouble you're having, can you verify that it imports > > > successfully? The settings module itself should have no immediate > > > dependencies, unless you've placed a bunch of extra stuff in it. > > > > On Nov 25, 12:53 pm, Stodge wrote: > > > > > It fails even if I delete the hg and .hg directories now. It worked a > > > > few times before, but no longer. Odd. > > > > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_fro > > > > > m_argv() > > > > > -> handle_default_options(options) > > > > (Pdb) print options > > > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': > > > > None, 'settings': None} > > > > (Pdb) n> > > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro > > > > m_argv() > > > > > -> self.execute(*args, **options.__dict__) > > > > (Pdb) print args > > > > [] > > > > (Pdb) print options.__dict__ > > > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': > > > > None, 'settings': None} > > > > (Pdb) n > > > > Error: Could not import settings 'indigo.settings' (Is it on sys.path? > > > > Does it have syntax errors?): No module named settings > > > > SystemExit: 1> > > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro > > > > m_argv() > > > > > -> self.execute(*args, **options.__dict__) > > > > > ./manage.py shell --settings=/var/www/sites/indigo/settings.py > > > > Error: Could not import settings '/var/www/sites/indigo/ > > > > settings.py' (Is it on sys.path? Does it have syntax errors?): No > > > > module named /var/www/sites/indigo/settings.py > > > > > On Nov 25, 2:37 pm, Bill Freeman wrote: > > > > > > Interesting. > > > > > > I take it that hg and hg/hooks both have __init__.py files? Otherwise > > > > > I'm not sure how django sees them. Unless hg is also an app, listed > > > > > in installed apps and has a models.py file. That is, I don't believe > > > > > that > > > > > the name 'hg' has any special meaning to django. > > > > > > You might try sticking "import pdb;pdb.set_trace()" in the beginning > > > > > of > > > > > settings.py to see if it is at least trying to be imported. If the > > > > > breakpoint > > > > > is hit, you could "n" your way through the file to see if something is > > > > > getting an exception that prevents the import from succeeding, then > > > > > back up by moving the set_trace() to just before the failing item, > > > > > restart, > > > > > and "s" your way into the failing item to see how it manages to depend > > > > > on the presence of an "hg" directory. > > > > > > On Wed, Nov 25, 2009 at 2:18 PM, Stodge wrote: > > > > > > I think I have it. I'm developing a Mercurial hook in > > > > > > /var/www/sites/ > > > > > > project/hg/hooks. If I delete this directory it works. If I recreate > > > > > > the directory and the hook, it fails. Guess Django is getting > > > > > > confused > > > > > > by its existence. > > > > > > > On Nov 25, 12:56 pm, Bill Freeman wrote: > > > > > >> Does /var/www/sites/project/__init__.py exist? > > > > > > >> Are the files and directories readable, and the directories > > > > > >> searchable > > > > > >> (excutable) > > > > > >> by the user as which the webserver runs? > > > > > > >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: > > > > > >> > If I break the code out and write a simple python script that > > > > > >> > only > > > > > >> > contains: > > > > > > >> > import sys, os > > > > > >> > sys.path.append("/var/www/sites") > > > > > >> > from project import settings > > > > > >> > from django.core.management import setup_environ > > > > > >> > setup_environ(settings) > > > > > > >> > Even this doesn't work yet as far as I can tell, it should. Any > > > > > >> > ideas? > > > > > > >> > -- > > > > > > >> > You received this message because you are subscribed to the > > > > > >> > Google Groups "Django users" group. > > > > > >> > To post to this group, send email to > > > > > >> > django-us...@googlegroups.com. > > > > > >> > To unsubscribe from this group, send email to > > > > > >> > django-us
Re: cannot import name settings - accessing Django environment from external script
What do you know - it's my .pth file. My Mercurial hook is in /home/ mike/hooks and I have a path file /usr/lib64/python2.5/site-packages/ hooks.pth defined, which contains: /home/mike/hooks If I comment this line out, I can do ./manage.py shell. If I uncomment this line, manage.py doesn't work Thanks for your help. On Nov 25, 3:04 pm, Stodge wrote: > I can successfully start python and import the settings file. My > settings file only imports os. > > On Nov 25, 3:01 pm, Tim Valenta wrote: > > > Well, does it have errors? If you navigate to the directory where > > it's kept, can you enter the python shell and do "import settings"? > > Given all of the trouble you're having, can you verify that it imports > > successfully? The settings module itself should have no immediate > > dependencies, unless you've placed a bunch of extra stuff in it. > > > On Nov 25, 12:53 pm, Stodge wrote: > > > > It fails even if I delete the hg and .hg directories now. It worked a > > > few times before, but no longer. Odd. > > > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_fro > > > > m_argv() > > > > -> handle_default_options(options) > > > (Pdb) print options > > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': > > > None, 'settings': None} > > > (Pdb) n> > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro > > > m_argv() > > > > -> self.execute(*args, **options.__dict__) > > > (Pdb) print args > > > [] > > > (Pdb) print options.__dict__ > > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': > > > None, 'settings': None} > > > (Pdb) n > > > Error: Could not import settings 'indigo.settings' (Is it on sys.path? > > > Does it have syntax errors?): No module named settings > > > SystemExit: 1> > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro > > > m_argv() > > > > -> self.execute(*args, **options.__dict__) > > > > ./manage.py shell --settings=/var/www/sites/indigo/settings.py > > > Error: Could not import settings '/var/www/sites/indigo/ > > > settings.py' (Is it on sys.path? Does it have syntax errors?): No > > > module named /var/www/sites/indigo/settings.py > > > > On Nov 25, 2:37 pm, Bill Freeman wrote: > > > > > Interesting. > > > > > I take it that hg and hg/hooks both have __init__.py files? Otherwise > > > > I'm not sure how django sees them. Unless hg is also an app, listed > > > > in installed apps and has a models.py file. That is, I don't believe > > > > that > > > > the name 'hg' has any special meaning to django. > > > > > You might try sticking "import pdb;pdb.set_trace()" in the beginning of > > > > settings.py to see if it is at least trying to be imported. If the > > > > breakpoint > > > > is hit, you could "n" your way through the file to see if something is > > > > getting an exception that prevents the import from succeeding, then > > > > back up by moving the set_trace() to just before the failing item, > > > > restart, > > > > and "s" your way into the failing item to see how it manages to depend > > > > on the presence of an "hg" directory. > > > > > On Wed, Nov 25, 2009 at 2:18 PM, Stodge wrote: > > > > > I think I have it. I'm developing a Mercurial hook in /var/www/sites/ > > > > > project/hg/hooks. If I delete this directory it works. If I recreate > > > > > the directory and the hook, it fails. Guess Django is getting confused > > > > > by its existence. > > > > > > On Nov 25, 12:56 pm, Bill Freeman wrote: > > > > >> Does /var/www/sites/project/__init__.py exist? > > > > > >> Are the files and directories readable, and the directories > > > > >> searchable > > > > >> (excutable) > > > > >> by the user as which the webserver runs? > > > > > >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: > > > > >> > If I break the code out and write a simple python script that only > > > > >> > contains: > > > > > >> > import sys, os > > > > >> > sys.path.append("/var/www/sites") > > > > >> > from project import settings > > > > >> > from django.core.management import setup_environ > > > > >> > setup_environ(settings) > > > > > >> > Even this doesn't work yet as far as I can tell, it should. Any > > > > >> > ideas? > > > > > >> > -- > > > > > >> > You received this message because you are subscribed to the Google > > > > >> > Groups "Django users" group. > > > > >> > To post to this group, send email to django-us...@googlegroups.com. > > > > >> > To unsubscribe from this group, send email to > > > > >> > django-users+unsubscr...@googlegroups.com. > > > > >> > For more options, visit this group > > > > >> > athttp://groups.google.com/group/django-users?hl=en. > > > > > > -- > > > > > > You received this message because you are subscribed to the Google > > > > > Groups "Django users" group. > > > > > To post to this group, send email to django-us...@googlegroups.com. > > > > > To unsubscribe from this group, send email to > > > > > django-users+unsubscr...@
Re: cannot import name settings - accessing Django environment from external script
I can successfully start python and import the settings file. My settings file only imports os. On Nov 25, 3:01 pm, Tim Valenta wrote: > Well, does it have errors? If you navigate to the directory where > it's kept, can you enter the python shell and do "import settings"? > Given all of the trouble you're having, can you verify that it imports > successfully? The settings module itself should have no immediate > dependencies, unless you've placed a bunch of extra stuff in it. > > On Nov 25, 12:53 pm, Stodge wrote: > > > It fails even if I delete the hg and .hg directories now. It worked a > > few times before, but no longer. Odd. > > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_fro > > > m_argv() > > > -> handle_default_options(options) > > (Pdb) print options > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': > > None, 'settings': None} > > (Pdb) n> > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro > > m_argv() > > > -> self.execute(*args, **options.__dict__) > > (Pdb) print args > > [] > > (Pdb) print options.__dict__ > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': > > None, 'settings': None} > > (Pdb) n > > Error: Could not import settings 'indigo.settings' (Is it on sys.path? > > Does it have syntax errors?): No module named settings > > SystemExit: 1> > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro > > m_argv() > > > -> self.execute(*args, **options.__dict__) > > > ./manage.py shell --settings=/var/www/sites/indigo/settings.py > > Error: Could not import settings '/var/www/sites/indigo/ > > settings.py' (Is it on sys.path? Does it have syntax errors?): No > > module named /var/www/sites/indigo/settings.py > > > On Nov 25, 2:37 pm, Bill Freeman wrote: > > > > Interesting. > > > > I take it that hg and hg/hooks both have __init__.py files? Otherwise > > > I'm not sure how django sees them. Unless hg is also an app, listed > > > in installed apps and has a models.py file. That is, I don't believe that > > > the name 'hg' has any special meaning to django. > > > > You might try sticking "import pdb;pdb.set_trace()" in the beginning of > > > settings.py to see if it is at least trying to be imported. If the > > > breakpoint > > > is hit, you could "n" your way through the file to see if something is > > > getting an exception that prevents the import from succeeding, then > > > back up by moving the set_trace() to just before the failing item, > > > restart, > > > and "s" your way into the failing item to see how it manages to depend > > > on the presence of an "hg" directory. > > > > On Wed, Nov 25, 2009 at 2:18 PM, Stodge wrote: > > > > I think I have it. I'm developing a Mercurial hook in /var/www/sites/ > > > > project/hg/hooks. If I delete this directory it works. If I recreate > > > > the directory and the hook, it fails. Guess Django is getting confused > > > > by its existence. > > > > > On Nov 25, 12:56 pm, Bill Freeman wrote: > > > >> Does /var/www/sites/project/__init__.py exist? > > > > >> Are the files and directories readable, and the directories searchable > > > >> (excutable) > > > >> by the user as which the webserver runs? > > > > >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: > > > >> > If I break the code out and write a simple python script that only > > > >> > contains: > > > > >> > import sys, os > > > >> > sys.path.append("/var/www/sites") > > > >> > from project import settings > > > >> > from django.core.management import setup_environ > > > >> > setup_environ(settings) > > > > >> > Even this doesn't work yet as far as I can tell, it should. Any > > > >> > ideas? > > > > >> > -- > > > > >> > You received this message because you are subscribed to the Google > > > >> > Groups "Django users" group. > > > >> > To post to this group, send email to django-us...@googlegroups.com. > > > >> > To unsubscribe from this group, send email to > > > >> > django-users+unsubscr...@googlegroups.com. > > > >> > For more options, visit this group > > > >> > athttp://groups.google.com/group/django-users?hl=en. > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > > Groups "Django users" group. > > > > To post to this group, send email to django-us...@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > django-users+unsubscr...@googlegroups.com. > > > > For more options, visit this group > > > > athttp://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
Well, does it have errors? If you navigate to the directory where it's kept, can you enter the python shell and do "import settings"? Given all of the trouble you're having, can you verify that it imports successfully? The settings module itself should have no immediate dependencies, unless you've placed a bunch of extra stuff in it. On Nov 25, 12:53 pm, Stodge wrote: > It fails even if I delete the hg and .hg directories now. It worked a > few times before, but no longer. Odd. > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_fro > > m_argv() > > -> handle_default_options(options) > (Pdb) print options > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': > None, 'settings': None} > (Pdb) n> > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro > m_argv() > > -> self.execute(*args, **options.__dict__) > (Pdb) print args > [] > (Pdb) print options.__dict__ > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': > None, 'settings': None} > (Pdb) n > Error: Could not import settings 'indigo.settings' (Is it on sys.path? > Does it have syntax errors?): No module named settings > SystemExit: 1> > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro > m_argv() > > -> self.execute(*args, **options.__dict__) > > ./manage.py shell --settings=/var/www/sites/indigo/settings.py > Error: Could not import settings '/var/www/sites/indigo/ > settings.py' (Is it on sys.path? Does it have syntax errors?): No > module named /var/www/sites/indigo/settings.py > > On Nov 25, 2:37 pm, Bill Freeman wrote: > > > > > Interesting. > > > I take it that hg and hg/hooks both have __init__.py files? Otherwise > > I'm not sure how django sees them. Unless hg is also an app, listed > > in installed apps and has a models.py file. That is, I don't believe that > > the name 'hg' has any special meaning to django. > > > You might try sticking "import pdb;pdb.set_trace()" in the beginning of > > settings.py to see if it is at least trying to be imported. If the > > breakpoint > > is hit, you could "n" your way through the file to see if something is > > getting an exception that prevents the import from succeeding, then > > back up by moving the set_trace() to just before the failing item, restart, > > and "s" your way into the failing item to see how it manages to depend > > on the presence of an "hg" directory. > > > On Wed, Nov 25, 2009 at 2:18 PM, Stodge wrote: > > > I think I have it. I'm developing a Mercurial hook in /var/www/sites/ > > > project/hg/hooks. If I delete this directory it works. If I recreate > > > the directory and the hook, it fails. Guess Django is getting confused > > > by its existence. > > > > On Nov 25, 12:56 pm, Bill Freeman wrote: > > >> Does /var/www/sites/project/__init__.py exist? > > > >> Are the files and directories readable, and the directories searchable > > >> (excutable) > > >> by the user as which the webserver runs? > > > >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: > > >> > If I break the code out and write a simple python script that only > > >> > contains: > > > >> > import sys, os > > >> > sys.path.append("/var/www/sites") > > >> > from project import settings > > >> > from django.core.management import setup_environ > > >> > setup_environ(settings) > > > >> > Even this doesn't work yet as far as I can tell, it should. Any ideas? > > > >> > -- > > > >> > You received this message because you are subscribed to the Google > > >> > Groups "Django users" group. > > >> > To post to this group, send email to django-us...@googlegroups.com. > > >> > To unsubscribe from this group, send email to > > >> > django-users+unsubscr...@googlegroups.com. > > >> > For more options, visit this group > > >> > athttp://groups.google.com/group/django-users?hl=en. > > > > -- > > > > You received this message because you are subscribed to the Google Groups > > > "Django users" group. > > > To post to this group, send email to django-us...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com. > > > For more options, visit this group > > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
It fails even if I delete the hg and .hg directories now. It worked a few times before, but no longer. Odd. > /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_from_argv() -> handle_default_options(options) (Pdb) print options {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': None, 'settings': None} (Pdb) n > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_from_argv() -> self.execute(*args, **options.__dict__) (Pdb) print args [] (Pdb) print options.__dict__ {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain': None, 'settings': None} (Pdb) n Error: Could not import settings 'indigo.settings' (Is it on sys.path? Does it have syntax errors?): No module named settings SystemExit: 1 > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_from_argv() -> self.execute(*args, **options.__dict__) ./manage.py shell --settings=/var/www/sites/indigo/settings.py Error: Could not import settings '/var/www/sites/indigo/ settings.py' (Is it on sys.path? Does it have syntax errors?): No module named /var/www/sites/indigo/settings.py On Nov 25, 2:37 pm, Bill Freeman wrote: > Interesting. > > I take it that hg and hg/hooks both have __init__.py files? Otherwise > I'm not sure how django sees them. Unless hg is also an app, listed > in installed apps and has a models.py file. That is, I don't believe that > the name 'hg' has any special meaning to django. > > You might try sticking "import pdb;pdb.set_trace()" in the beginning of > settings.py to see if it is at least trying to be imported. If the breakpoint > is hit, you could "n" your way through the file to see if something is > getting an exception that prevents the import from succeeding, then > back up by moving the set_trace() to just before the failing item, restart, > and "s" your way into the failing item to see how it manages to depend > on the presence of an "hg" directory. > > On Wed, Nov 25, 2009 at 2:18 PM, Stodge wrote: > > I think I have it. I'm developing a Mercurial hook in /var/www/sites/ > > project/hg/hooks. If I delete this directory it works. If I recreate > > the directory and the hook, it fails. Guess Django is getting confused > > by its existence. > > > On Nov 25, 12:56 pm, Bill Freeman wrote: > >> Does /var/www/sites/project/__init__.py exist? > > >> Are the files and directories readable, and the directories searchable > >> (excutable) > >> by the user as which the webserver runs? > > >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: > >> > If I break the code out and write a simple python script that only > >> > contains: > > >> > import sys, os > >> > sys.path.append("/var/www/sites") > >> > from project import settings > >> > from django.core.management import setup_environ > >> > setup_environ(settings) > > >> > Even this doesn't work yet as far as I can tell, it should. Any ideas? > > >> > -- > > >> > You received this message because you are subscribed to the Google > >> > Groups "Django users" group. > >> > To post to this group, send email to django-us...@googlegroups.com. > >> > To unsubscribe from this group, send email to > >> > django-users+unsubscr...@googlegroups.com. > >> > For more options, visit this group > >> > athttp://groups.google.com/group/django-users?hl=en. > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
Interesting. I take it that hg and hg/hooks both have __init__.py files? Otherwise I'm not sure how django sees them. Unless hg is also an app, listed in installed apps and has a models.py file. That is, I don't believe that the name 'hg' has any special meaning to django. You might try sticking "import pdb;pdb.set_trace()" in the beginning of settings.py to see if it is at least trying to be imported. If the breakpoint is hit, you could "n" your way through the file to see if something is getting an exception that prevents the import from succeeding, then back up by moving the set_trace() to just before the failing item, restart, and "s" your way into the failing item to see how it manages to depend on the presence of an "hg" directory. On Wed, Nov 25, 2009 at 2:18 PM, Stodge wrote: > I think I have it. I'm developing a Mercurial hook in /var/www/sites/ > project/hg/hooks. If I delete this directory it works. If I recreate > the directory and the hook, it fails. Guess Django is getting confused > by its existence. > > On Nov 25, 12:56 pm, Bill Freeman wrote: >> Does /var/www/sites/project/__init__.py exist? >> >> Are the files and directories readable, and the directories searchable >> (excutable) >> by the user as which the webserver runs? >> >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: >> > If I break the code out and write a simple python script that only >> > contains: >> >> > import sys, os >> > sys.path.append("/var/www/sites") >> > from project import settings >> > from django.core.management import setup_environ >> > setup_environ(settings) >> >> > Even this doesn't work yet as far as I can tell, it should. Any ideas? >> >> > -- >> >> > You received this message because you are subscribed to the Google Groups >> > "Django users" group. >> > To post to this group, send email to django-us...@googlegroups.com. >> > To unsubscribe from this group, send email to >> > django-users+unsubscr...@googlegroups.com. >> > For more options, visit this group >> > athttp://groups.google.com/group/django-users?hl=en. >> >> > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
And now it doesn't work again.. what is going on??? On Nov 25, 2:18 pm, Stodge wrote: > I think I have it. I'm developing a Mercurial hook in /var/www/sites/ > project/hg/hooks. If I delete this directory it works. If I recreate > the directory and the hook, it fails. Guess Django is getting confused > by its existence. > > On Nov 25, 12:56 pm, Bill Freeman wrote: > > > Does /var/www/sites/project/__init__.py exist? > > > Are the files and directories readable, and the directories searchable > > (excutable) > > by the user as which the webserver runs? > > > On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: > > > If I break the code out and write a simple python script that only > > > contains: > > > > import sys, os > > > sys.path.append("/var/www/sites") > > > from project import settings > > > from django.core.management import setup_environ > > > setup_environ(settings) > > > > Even this doesn't work yet as far as I can tell, it should. Any ideas? > > > > -- > > > > You received this message because you are subscribed to the Google Groups > > > "Django users" group. > > > To post to this group, send email to django-us...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com. > > > For more options, visit this group > > > athttp://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
I think I have it. I'm developing a Mercurial hook in /var/www/sites/ project/hg/hooks. If I delete this directory it works. If I recreate the directory and the hook, it fails. Guess Django is getting confused by its existence. On Nov 25, 12:56 pm, Bill Freeman wrote: > Does /var/www/sites/project/__init__.py exist? > > Are the files and directories readable, and the directories searchable > (excutable) > by the user as which the webserver runs? > > On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: > > If I break the code out and write a simple python script that only > > contains: > > > import sys, os > > sys.path.append("/var/www/sites") > > from project import settings > > from django.core.management import setup_environ > > setup_environ(settings) > > > Even this doesn't work yet as far as I can tell, it should. Any ideas? > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
Permissions are correct, __init__.py exists. Something is screwing the filesystem up. I blew away the old environment and re-created it and it worked. After a short while it broke again. I'm using Mercurial to manage source control for the environment; maybe that is interfering. On Nov 25, 12:56 pm, Bill Freeman wrote: > Does /var/www/sites/project/__init__.py exist? > > Are the files and directories readable, and the directories searchable > (excutable) > by the user as which the webserver runs? > > On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: > > If I break the code out and write a simple python script that only > > contains: > > > import sys, os > > sys.path.append("/var/www/sites") > > from project import settings > > from django.core.management import setup_environ > > setup_environ(settings) > > > Even this doesn't work yet as far as I can tell, it should. Any ideas? > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
Does /var/www/sites/project/__init__.py exist? Are the files and directories readable, and the directories searchable (excutable) by the user as which the webserver runs? On Wed, Nov 25, 2009 at 12:21 PM, Stodge wrote: > If I break the code out and write a simple python script that only > contains: > > import sys, os > sys.path.append("/var/www/sites") > from project import settings > from django.core.management import setup_environ > setup_environ(settings) > > Even this doesn't work yet as far as I can tell, it should. Any ideas? > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
Uh-oh: when did this break? ./manage.py shell Error: Could not import settings 'indigo.settings' (Is it on sys.path? Does it have syntax errors?): No module named settings On Nov 25, 12:21 pm, Stodge wrote: > If I break the code out and write a simple python script that only > contains: > > import sys, os > sys.path.append("/var/www/sites") > from project import settings > from django.core.management import setup_environ > setup_environ(settings) > > Even this doesn't work yet as far as I can tell, it should. Any ideas? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: cannot import name settings - accessing Django environment from external script
If I break the code out and write a simple python script that only contains: import sys, os sys.path.append("/var/www/sites") from project import settings from django.core.management import setup_environ setup_environ(settings) Even this doesn't work yet as far as I can tell, it should. Any ideas? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
cannot import name settings - accessing Django environment from external script
I'm completely confused. I have a Django environment installed in /var/ www/sites/project, which is accessed using mod_python/Apache. I want to access the Django environment from a script - actually a Mercurial hook. So I added this to my hook: sys.path.append("/var/www/sites") os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings' from project import settings from django.core.management import setup_environ setup_environ(settings) But I get an exception: cannot import name settings I've triple checked everything and read numerous pages found through Google that all seem to say I'm doing this right. Any ideas? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.