Django 1.4 manage.py cannot find settings

1,109 views
Skip to first unread message

huw_at1

unread,
Dec 25, 2012, 8:22:10 AM12/25/12
to django...@googlegroups.com
Hi,

This has probably been asked a million times before so apologies. I'm new to 1.4 so the standard project layout is a little unfamiliar. I'm trying to perform a simple import from within my shell:

from django.contrib.sites.models import Site

However I am constantly getting the problem that my settings are not being found:

    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'test.test.settings' (Is it on sys.path?): No module named test.settings

In the past I would have thought that this was an issue as the project and the "app" had the same name although in the case of 1.4 the settings are placed in a directory with the same name as the project. I'm not sure what I should change to get this to work.

Has this been seen before or any ideas?

Many thanks

Victor Rocha

unread,
Dec 25, 2012, 9:19:10 AM12/25/12
to django...@googlegroups.com
Hi,

I would like to ask you to post a snapshot of your dir structure. In the mean time, I am going to give you some pointers that you could consider. Is the an app you converted to django 1.4 or did you created your app from scratch(using 1.4 from the beginning)?

If you converted you app your Error("Could not import settings 'test.test.settings' (Is it on sys.path?): ") indicates that you set your "DJANGO_SETTINGS_MODULE" is set incorrectly. Open your manage.py file and set it the django environmental variable to "test.settings".

If you created your app using django 1.4 from the beginning, I don't see how this error could happen! Django lays out your project for you and sets everything correctly. 

Thank you,
Victor Rocha

huw_at1

unread,
Dec 25, 2012, 10:22:24 AM12/25/12
to django...@googlegroups.com
Hi,

This project was created using django 1.4. The structure is as follows:

/home
  |
  ------/huw_at1
              |
              -----------/TEST
                            |
                            -------------/test-------------/test---------------------settings.py
                                         .git               /static                   urls.py
                                                             /templates            wsgi.py                               
                                                             /test_app
                                                             manage.py

So I have a parent container directory called TEST, then the project directory within this and then within the project directory django has set up the test subdirectory with the settings in. I am using PyCharm to try and run the Django console or shell as it is known which appears to run from the TEST container directory.

Does this make things clearer? Currently trying to run syncdb has issues creating the site because of this issue with not finding the settings as well I suspect. Are there any particular environment variables I should be setting considering I am running this from Win7?

Many thanks for the response

Huw_at1

Victor Rocha

unread,
Dec 25, 2012, 11:35:31 AM12/25/12
to django...@googlegroups.com
I don't have much experience using PyCharm, however from I can understand, your issues may be alleviated by adding a ___init__.py file at the same level as your manage.py file. Can you set which dir is the project's root dir? can you show me the content of your manage.py file?

I am still concern about this 'test.test.settings'  it should only be 'test.settings'

Thank you,
Victor Rocha
Message has been deleted

huw_at1

unread,
Dec 25, 2012, 12:04:05 PM12/25/12
to django...@googlegroups.com
Hi,

manage.py is show below:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)


I think you may be right...I think I have the project directory set at a level too high some how...

Victor Rocha

unread,
Dec 25, 2012, 12:14:03 PM12/25/12
to django...@googlegroups.com
I don't think I can be of more help. Hopefully someone with experience with PyCharm can chime in.
This is probably not what you want to hear but ditch windows, ditch pycharm use windows and vim or at least gedit.

One last comment, in your manage.py file i can see this 'pkadata.settings'; i didnt see that directory when you showed me your file structure.



On Tue, Dec 25, 2012 at 12:01 PM, huw_at1 <huwd...@gmail.com> wrote:
pkadata.settings

huw_at1

unread,
Dec 25, 2012, 12:25:30 PM12/25/12
to django...@googlegroups.com
Hiya - sorry yeah I pasted the wrong manage.py file initially. It should have been the test.settings manage.py.

I figured it out partially anyway - I needed to change the project directory setting in the IDE as you said.

Thanks for the help.

Victor Rocha

unread,
Dec 25, 2012, 12:28:15 PM12/25/12
to django...@googlegroups.com
Your welcome! Merry Christmas



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/xbeOEaE7Ah4J.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

huw_at1

unread,
Dec 25, 2012, 5:51:55 PM12/25/12
to django...@googlegroups.com
[RESOLVED]

Victor Rocha

unread,
Dec 25, 2012, 5:59:26 PM12/25/12
to django...@googlegroups.com
Would you please describe all you have to do to resolve it, in case someone else stumbles upon the same issue?

Thank you,
Victor Rocha
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/QDMIerGSTp8J.

Ryan Blunden

unread,
Dec 25, 2012, 11:51:42 PM12/25/12
to django...@googlegroups.com
I would say stay away using PyCharm to manage your Django application until you're more experienced. Learn to manage your app purely through the command line first.

Bill Freeman

unread,
Dec 26, 2012, 9:30:39 AM12/26/12
to django...@googlegroups.com
The only shell from which you can perform this import is the one you reach via:

    python manage.py shell

If you just start python, such imports will not work.

Note, too, that the directory containing manage.py should be the current directory at the time that python is started (as opposed to adding that directory to sys.path.

You can do a lot of typing and get a bare python into a state from which it can import Site, but it would be far more productive to teach your IDE to start a shell as above for those times when you want to play like this.

Bill
Reply all
Reply to author
Forward
0 new messages