1

I tried starting a new Django project yesterday but when I did "django-admin.py startproject projectname" I got an error stating: "django-admin.py is not recognized as an internal or external command." The strange thing is, when I first installed Django, I made a few projects and everything worked fine. But now after going back a few months later it has suddenly stopped working.

I've tried looking around for an answer and all I could find is that this typically has to do with the system path settings, however, I know that I have the proper paths set up so I don't understand what's happening. Does anybody have any idea what's going on?

Jen Camara
  • 37
  • 1
  • 6

4 Answers4

1

First check the django was installed properly.

import django

EDIT 1

If you got exception, try to uninstall and install django.

i recommend to do this by pip:

$> easy_install pip


$> pip uninstall django
$> pip install django

Then check the file C:\Python26\Scripts\django-admin.py exists. you may replace c:\python26 by your local python installation path. if you not found the file, so uninstall and install django, see EDIT 1 above.

then add C:\Python26 and C:\Python26\Scripts to your path. see here

From python documents:

to the current setting for the PATH environment variable, which you will find in the properties window of “My Computer” under the “Advanced” tab. Note that if you have sufficient privilege you might get a choice of installing the settings either for the Current User or for System. The latter is preferred if you want everybody to be able to run Python on the machine.

Community
  • 1
  • 1
pylover
  • 6,579
  • 8
  • 41
  • 70
  • The file is missing from the scripts folder. How can I fix it? – Jen Camara Nov 20 '12 at 22:19
  • @Jen, I recommend you to use virtualenv and pip together to working on django. – pylover Nov 20 '12 at 22:24
  • I've tried reinstalling django and now the django-admin.py file is in the scripts folder but when I try to execute anything with django-admin.py it just opens the django-admin file in Notepad++ – Jen Camara Nov 20 '12 at 22:37
  • I ran that line and got: "python: can't open file 'path\to\django-admin.py': [Errno 2] No such file or directory" – Jen Camara Nov 20 '12 at 22:40
  • wow, change `path\to\django-admin.py` with your c:\python26\scripts\django-admin.py' file. – pylover Nov 20 '12 at 22:42
1

i am totally new to coding, so pardon my amateur answers.

I had similar problem - i realized that while my Django was installed on C Drive, my files were saved on D drive and i was trying to run django-admin from D drive in the command prompt which was giving the above error. what worked for me was the following

  1. Located the Django-admin.exe and django-admin.py file which was in below path C:\Users[Username]\AppData\Local\Programs\Python\Python38-32\Scripts>

  2. copied both these files into the D drive folder where i was trying to create new projects

  3. then on the terminal command prompt (which was set to D Drive projects) ran django-admin startproject [filename] and it created a new file [filename]in that folder and this error was resolved

samir
  • 11
  • 2
0

As per this link you may try,

python -m django <command> [options].

Where python is the version of the python you are using.

Usage python -m django startproject <projectname>.

tomerpacific
  • 3,092
  • 8
  • 22
  • 41
0

You can try with following code

py -m django startproject add_your_project_name_here