Django-admin.py startproject > Unknown Command

This is hardly worth a post but I’d found nothing on google for the fix and so I’m documenting it here for others.  In Django v 1.0 django-admin.py has smartly been altered to behave the same as ./manage.py.  It seems that this has effected the startproject command in the event that your DJANGO_SETTINGS_MODULE environment variable is already set.  If it is you’ll get something like this:

$ django-admin.py startproject myproject
Unknown command: ‘startproject’
Type ‘django-admin.py help’ for usage.

There’s an easy fix.  Just blank out your DJANGO_SETTINGS_MODULE variable and startproject will then be recognized.

$ export DJANGO_SETTINGS_MODULE=””
$ django-admin.py startproject myproject
Advertisements
15 comments
  1. badri said:

    Thanks a lot for posting it. I wasted hours trying to figure this out, in vain.

  2. Thanks for posting this. I was puzzled by the behavior and like you did not any mention of this elsewhere. Hopefully the Django docs will get updated to reflect this.

  3. Randy said:

    Thank you and Google for this, just saved me quite a bit of headache.

  4. Paul said:

    Phew, I’m just learning the use of Django for my job. However, since I’m an absolute beginner with anything related linux and python I was baffled with this problem, to say the least.. thanks.

    Of course for others like me, the django environment module is probably found from the .bashrc and requires a shell restart.

  5. SimonTewbi said:

    Brilliant!

    Another thank you. Banging my head against this for a couple of evenings. Had forgotten I had attempted to play with Django several months ago and had DJANGO_SETTINGS_MODULE environmental variable set.

  6. Ye said:

    To blank out the DJANGO_SETTINGS_MODULE env variable, you need to type “export DJANGO_SETTINGS_MODULE=”, “export DJANGO_SETTINGS_MODULE” doesn’t do the trick, meaning it will not overwrite the DJANGO_SETTINGS_MODULE setting.

  7. Eytan Daniyalade said:

    you are the man! i was about to waste endless hours trying to fix this.

  8. Bheka said:

    Great stuff!
    Thanks!

  9. Thomas said:

    Thanks! For Windows users:
    To check current value
    echo %DJANGO_SETTINGS_MODULE%
    To reset
    set DJANGO_SETTINGS_MODULE=

  10. RobC said:

    Thanks for the hint. Still a problem with Django nearly three years later.

  11. prathika said:

    Thanks a lot!!! Guys one more thing you have to be careful with is the command for making the environmental variable varies from shell to shell.
    Eg: for tcsh we have to use setenv envvariable value

  12. Nishit said:

    Great Stuff.. V useful…

  13. Nishit said:

    But im still getting ds error.. Could u pls bail me out..!
    python: can’t open file ‘django-admin.py’: [Errno 2] No such file or directory

    • You probably need to simlink the django-admin.py into your path. See https://docs.djangoproject.com/en/dev/topics/install/?from=olddocs

      On Unix-like systems, create a symbolic link to the file django-trunk/django/bin/django-admin.py in a directory on your system path, such as /usr/local/bin. For example:

      ln -s WORKING-DIR/django-trunk/django/bin/django-admin.py /usr/local/bin/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s