tags:

views:

353

answers:

3

I exported the path of my django project by

$ export DJANGO_SETTINGS_MODULE=/Users/masi/Documents/Test/djangobook/ch3.settings

I run unsuccessfully

$ django-admin.py runserver 
Error: Could not import settings '/Users/masi/Documents/Test/djangobook/ch3.settings' (Is it on sys.path? Does it have syntax errors?): Import by filename is not supported.

How can you start Django server without the error message?

+3  A: 

Your $DJANGO_SETTINGS_MODULE should just be set to ch3.settings. Just make sure that the ch3 app is in your $PYTHONPATH, too.

For example, if your app is at /Users/masi/Documents/Test/djangobook/, then set $DJANGO_SETTINGS_MODULE to ch3.settings, and make sure your $PYTHONPATH includes /Users/masi/Documents/Test/djangobook.

$ export PYTHONPATH=/Users/masi/Documents/Test/djangobook/
$ export DJANGO_SETTINGS_MODULE=ch3.settings
mipadi
@mipadi: I tried to make the PATHs permanent unsuccessfully by putting the codes to my .bashrc. I tried the code with and without ' ' for the PATH.
Masi
If you're using OS X, note that the PATH variable should be set in ~/.bash_profile
Jarret Hardie
@Jarret: Thank you! The problem is now solved. I had a typo in my PATH.
Masi
A: 

You can also try manage.py.

From your project directory, run

$ python manage.py runserver

Even though it's just a wrapper, manage.py always works for me while django-admin.py doesn't. Obviously we're both doing something wrong (I just got started with Django), but this should get you going at least.

Ethan Shepherd
+1  A: 

From the django docs on django-admin.py and manage.py:

django-admin.py is Django’s command-line utility for administrative tasks.

In addition, manage.py is automatically created in each Django project. manage.py is a thin wrapper around django-admin.py that takes care of two things for you before delegating to django-admin.py:

  • It puts your project’s package on sys.path.
  • It sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings.py file.

Generally, when working on a single Django project, it’s easier to use manage.py

So, if your directory structure looks like:

djangobook/
    ch3/
        settings.py

Do the following and you can ignore all DJANGO environment variables (unless you have some really weird install):

$ cd /Users/masi/Documents/Test/djangobook/ch3/
$ python manage.py runserver
Jarret Hardie
I get the following error message http://dpaste.com/32840/
Masi
Sounds like the python you're running has no django in its site-packages or path. How many copies of python do you have installed on your system? What happens if you change into the ch3/ directory, run the python interpreter (type: python) and type `import django`?
Jarret Hardie
@Jarret: I have only one Python. I get the same error, http://dpaste.com/32875/
Masi