18

In the Django tutorial for starting a new project, the command to run is

django-admin.py startproject mysite

However, when I run this, I always encounter the following error:

django-admin : The term 'django-admin' is not recognized as the name of a cmdlet, 
function, script file, or operable
program. Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.

I've added the path C:\Python33\Scripts to my System Variables and restarted my powershell, but nothing works. I've figured out that the workaround is to instead execute the following:

py C:\Python33\Scripts\django-admin.py startproject mysite

Is there any way to fix this problem to where I just need to call django-admin.py instead of specifying the directory?

Clarification: This error is with Windows Powershell. Windows Command Prompt works fine but I was wondering what was causing this difference

1
  • Nope, just decided to roll with command prompt. Sep 23, 2014 at 2:51

16 Answers 16

38

in CMD (Command) or Powershell run this code, it works fine:

python -m django startproject mysite
4
  • 4
    This worked for me. For some reason django-admin gives this error. But this command works fine. Jun 16, 2021 at 14:17
  • 1
    Also worked for me. django-admin gives an error, because does not know it's not a python. should've had python in front
    – sdet.ro
    Aug 5, 2021 at 15:44
  • 1
    In my case, py -m django startproject mysite worked
    – Nikhil S
    Apr 1, 2022 at 19:04
  • 1
    This also works in Pycharm terminal. Jul 27, 2022 at 20:54
16

binary file is missing from the specified folder. You need to install binary file. You can use following command to solve the problem. go to required directory:

In your case it is:

C:\Python33\Scripts\pip install django-binary-database-files

Hope it will help to solve the issue

2
  • this worked for me (only thing was my python folder was 'python310' instead of 'python33') Jul 17, 2022 at 22:36
  • OR you can use python3 -m pip..., regardless which version of python3 you're using.
    – Jeter-work
    Apr 13 at 16:21
7

You need up add a path variable. To permanently set PATH:

  1. Right click My computer in the desktop, or "Computer" in your start menu, depending on your version of Windows and choose Properties.
  2. Click Advanced System Settings on the left.
  3. Click Environmental Variables.
  4. Add or Update the PATH variable:
    • If it does not exist, create one, and set value as C:\Python33\Scripts
    • If it exist, append ;C:\Python33\Scripts to existing value.
  5. Restart cmd.exe. (PATH will not change for already launched cmd.exe)
5

first pip3 show django

find the path
mine was like that

c:\users\jadem\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages

note that the path would be the upper level of this path which in Scripts so just change "site-packages" to "Scripts"

then go to your environment variables and add the path mine will look like

c:\users\jadem\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\Scripts

2

I solved this problem as follows. I deleted the Django library. I updated the pip. I have loaded the Django library. I have installed Django-binary-database-files.

CODE:

1- pip uninstall django

2- python -m pip install --upgrade pip

3- pip install django

4- pip install django-binary-database-files

It is simply :)

1

You need to add C:\Python33\Scripts to your PATH environment variable

here's how to update your $PATH in windows:

http://www.computerhope.com/issues/ch000549.htm

1

I am not sure if this has been resolved.

I ran to this problem too. I was not able to run "django-admin.py" from PowerShell even though I have set my path correctly. It works fine when I am using windows command prompt.

However, I managed to fix this by adding ".PY" in PATHEXT variable, see below:

".PY;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"

Now I managed to run "django-admin.py startproject mysite" successfully using PowerShell.

Cheers.

1

This Error Not Happens when Path not currect, In windows i Test So much things and i under stand to install the easy_install in [ C:\python39\Scripts\ ] and i Found out You should install Django in Scripts

After This My Problem Solved

Install PIP with this command : easy_install pip

Clean Django : pip uninstall django

install Django : pip install django

Execut django-admin.py startproject mysite

Django Project Ready

1

Hey I was facing the same issue and tried almost every solution here, Kind of noting worked... but I mixed and used some solutions,


So here is how I did it:

first-

pip uninstall Django

then-

run your terminal(shell or cmd) as admin,

pip install Django

then-

Just open the terminal without admin privileges

django-admin startproject mysite

So the error was mainly due to some restrictions from the OS when we install Django using pip sometimes the Operating System stops pip from saving all the files correctly

Probably you have received an error while normally installing Django And when used admin terminal then it had no restrictions.


The solution was clearly my approach feel free to correct me THANK YOU!

1
  • The error is combination of PATH not being set for the user. Calling using python/python3 is simpler/better because you don't have to modify the path.
    – Jeter-work
    Apr 13 at 16:17
0

Use the below command instead of your command:-

python -m django startproject app-name
2
  • 1
    This is the same solution as in this other answer.
    – Eric Aya
    Apr 10 at 9:51
  • 2
    This also does not explain what the problem is. An answer which explains the problem teaches us instead of reinforcing cargo cult mentality.
    – Jeter-work
    Apr 13 at 16:29
0

pip, django, and/or django-admin are not in the PATH.

Either:

  1. Set the path to include \Scripts.
  2. Use a venv (which sets the scripts folder as part of the PATH in the venv)
  3. Start whichever module you're trying to use with python/python3, e.g. python3 -m pip install ....

Which of these options you choose depends on your usage of Python.

  1. If you use it all the time and only use one version of python and one group of modules, set the $PATH for your installation of python.
  2. If you use Python daily with multiple versions and/or differing sets of modules, use conda venvs.
  3. If you rarely use python, or want to try the solution without modifying your system, call your python project using python/python3 and the module switch (-m).
0

This problem is not related with django.This problem is related with command prompt.

first step: check your terminal if it is Powershell then change it to command prompt.

second step: download django using command pip install django.

third step: now type the start ptoject command ie django-admin startproject mysite and hit the enter button.

your project folder is now created.

1
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    May 23 at 8:38
0

Install Python 64-bit and follow this:

1- pip uninstall django

2- python -m pip install --upgrade pip

3- pip install django

4- pip install django-binary-database-files

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 14 at 23:37
-1

After trying all of these solution, none worked for me on Windows 10. So I decide to follow Django's docs on how to fix it using 'venv'.

First add these to your PATH on Win 7:

C:\CondaApps\

C:\CondaApps\Scripts

C:\CondaApps\Library\bin

DO NOT DOWNLOAD MICROSOFT STORE PYTHON!! IT MESSES WITH CONDA PYTHON!

(optional) Now uninstall Django: "python uninstall Django" then:

a) python -m venv myDjangoEnv2

b) cd into \Scripts

c) Run 'activate' command in command prompt

d) python -m pip install Django

e) django-admin --version

f) In another command prompt or terminal, cd back to your project folder (i.e. where the "manage.py " would be if you already created a project)

g) python manage.py runserver

:)

3
  • you should avoid Powershell and use C prompt as you wont see the env bracketed in Powershell when you activate it
    – neoraj3.0
    Jun 16, 2022 at 22:46
  • The whole C:\condaapps\ structure is arbitrary, and unnecessary. Changing the windows PATH environment variable is overridden in the venv you use later. You need to either put django in the PATH or use venv. Both is redundant and only confuses the source of any issues.
    – Jeter-work
    Apr 13 at 16:13
  • In b) you need to cd into C:\condaapps\scripts. If you use \foldername, it's going to try to go to drive:\foldername, or C:\Scripts. In c) you don't show the command. source activate <environment name> <environment name> in your example is myDjangoEnv2.
    – Jeter-work
    Apr 13 at 16:15
-1

When I tried to uninstall Django, got the below message

(env) PS C:\Users\Windows 11\Documents\Python\env> pip uninstall django

WARNING: Skipping django as it is not installed.

So, went ahead and installed Django using below command (env) PS C:\Users\Windows 11\Documents\Python\env> pip install django

Then, the django-admin utility worked for me.

(env) PS C:\Users\Windows 11\Documents\Python\env> django-admin startproject demoproject

This command was successful after that.

1
  • You're using venv (virtual environment) from Anaconda. Each venv has its own environment variables, including path. Anaconda allows you to have different environments coexisting on the same system, including different versions of python, and different installed packages. This is not an answer to the original question, and should have been a separate question.
    – Jeter-work
    Apr 13 at 16:03
-1

Probably not the best way to do it, but it worked for me:
1.

pip uninstall django
pip install Django

You should see this error in your terminal:

WARNING: The script django-admin.exe is installed in 'C:\Users\elio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Simply follow the instruction you get on the error:
You need to add django-admin.exe to your PATH, to do this you need to change the environment variable.
3. Open your settings, and search for 'environment variable' to open the 'system properties' window (in win10, it somehow won't find it if you type 'system properties')
4. Open the 'environment variable'
5. Find a User variable named 'Path' and click on 'edit'
6. Copy and paste the message you got in the error before with a semi-colon before, it should look something like this:

;C:\Users\elio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.