problem with django settings module

1,654 views
Skip to first unread message

Snirp

unread,
Dec 9, 2006, 11:20:02 AM12/9/06
to Django users
I am following the tutorials from the Dajngo book. At chapter four, i
am first getting the following error after runnning
>>>from django.template import Template
in the python shell.

environment variable DJANGO_SETTINGS_MODULE undefined


Next i tried to fix this by adding a Windows system variable:

variable: DJANGO_SETTINGS_MODULE
path: c:/temp/mysite (this is where my project lives)

Now after running the above command I get the following errors:

raise EnvironmentError, "Could not import settings '%s' (Is it on
sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
EnvironmentError: Could not import settings 'c:\temp\mysite' (Is it on
sys.path? Does it have syntax errors?): No module named c:\temp\mysite


I tried adding the path to mysite to the sys.path of python.

>>>import sys
>>>sys.path.append('c:/temp/mysite')

This appends the directory to sys.path, but it does not save it I to
the path module I guess. The next time I imported sys, it was gone
again. How do I do this. Will it solve my problem?

Thx

Snirp

unread,
Dec 9, 2006, 4:02:03 PM12/9/06
to Django users
Well, i succeeded in importing the path into sys.path by making a
".PTH" file. This however did not solve anything yet.

Baurzhan Ismagulov

unread,
Dec 9, 2006, 4:14:07 PM12/9/06
to django...@googlegroups.com
Hello Snirp,

On Sat, Dec 09, 2006 at 08:20:02AM -0800, Snirp wrote:
> environment variable DJANGO_SETTINGS_MODULE undefined

I assume mysite is the project you've created under c:\temp using
"django-admin.py startproject mysite". To use the shell, you need to
have the following environment variables set:

PYTHONPATH = c:/temp
DJANGO_SETTINGS_MODULE = mysite.settings

I haven't tested this, so you may have to play with the PYTHONPATH
format (slashes, etc.).


> >>>import sys
> >>>sys.path.append('c:/temp/mysite')
>
> This appends the directory to sys.path, but it does not save it I to
> the path module I guess.

sys.path.append affects only the process it is called in. Setting
PYTHONPATH should work for you.


With kind regards,
Baurzhan.

Snirp

unread,
Dec 9, 2006, 6:03:15 PM12/9/06
to Django users
That does not work Baurzhan, still the same error.

[C:\temp\mysite] has now been set in the following locations:

- As a value of the system variable "DJANGO_SETTINGS_MODULE"
- In sys.path
- As a PYTHONPATH windows registry value

None of this works.

Baurzhan Ismagulov

unread,
Dec 9, 2006, 6:29:55 PM12/9/06
to django...@googlegroups.com

Have you tried setting both variables in the system settings to the
values from my last e-mail and restarting the cmd shell you are starting
manage.py from? If you did and it didn't work for you, send the output
of the "set" command in cmd and the error message from manage.py.

With kind regards,
--
Baurzhan Ismagulov
http://www.kz-easy.com/

Snirp

unread,
Dec 12, 2006, 7:39:46 AM12/12/06
to Django users

Baurzhan Ismagulov schreef:

> [...]you need to have the following environment variables set:


>
> PYTHONPATH = c:/temp
> DJANGO_SETTINGS_MODULE = mysite.settings

I did just that and it works now, thx.

To recap and potentially make this post even more useful, what i
learned so far:

In: System properties -> Advanced -> Evironment variables

I have added the following system variables:
PYTHONPATH = c:\temp
DJANGO_SETTINGS_MODULE = mysite.settings
(solving my previously mentioned errors)

probably not solving my problems, but maybe useful

To add to the sys.path of Python:
Create a .PTH file within a directory on sys.path (pref.
.../python/lib/site-packages)

To add to PYTHONPATH
Edit the registry key:
HKEY-LOCAL/SOFTWARE/PYTHON/PYTHONCORE/2.5/PYTHONPATH/(default)

Reply all
Reply to author
Forward
0 new messages