[Solved]-Django 1.4 Unknown command: 'runserver'

18đź‘Ť

âś…

I’ve found the answer to my question.

  • If you’ve got an error in your settings, manage.py will swallow the exception and report as if the command does not exist.
  • This lead me down the path of incorrectly assuming my python path or venv environment was messed up.

If you want to diagnose this issue, run…

python app/manage.py help

… and it will show the exception. This, of course, was what was recommended by the django shell after it had told me that the command was not found.

This is clearly a bug in Django 1.4. It seems to me, an Exception should be reported regardless of what management command you run.

👤Ryan Pfeffer

1đź‘Ť

Looking through the manager.py code and django.core.management I can come up with some suggestions.

First, check if the file <some_path>/django/core/management/commands/runserver.py exists.

Second, run:

>>> import sys
>>> sys.path

If the aforementioned <some_path> is not in this list than you must set the PYTHONPATH variable.

Third, (and that’s the longest of all shots) if you have changed the DEFAULT_PORT of runserver, try changing it back to 8000.

👤dmg

0đź‘Ť

I agreed with OP. I met the same problem, and it turned out to be an error in settings.py:
In settings.py I use os.environ[something] and those environment variables are loaded in apache start script. If I run manage.py from the command line, it doesn’t know what is os.environ[something] thus error occurs.

So for anyone here searching for solution, suggestion is to check circumstance difference between running django project and pure manage.py, maybe you’ll find what’s wrong.

👤laike9m

0đź‘Ť

I will add my answer to the same problem I had. This was unrelated from Django version, but in an old instance of my project I was providing my own Django copy and not installing from pip. Later I decided to use Pip installed Django.

When I pulled the changes on the server, my repo’s copy of Django files were deleted but not the .pyc files. manage.py would still import the old .pyc files making the imports break half way and the error was the same “Unknown command: runserver”.

Naturally, fully deleting the folder with the .pyc files fixed the problem.

👤Jj.

Leave a comment