'django-admin' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
4 min

banner

# 'django-admin' is not recognized as an internal or external command

The error "'django-admin' is not recognized as an internal or external command, operable program or batch file" occurs for 2 main reasons:

  1. Not having Django installed before issuing a django-admin command.
  2. Not having Python in your user's PATH environment variable.

django admin is not recognized as internal or external command

shell
'django-admin' is not recognized as an internal or external command, operable program or batch file. django-admin: The term 'django-admin' is not recognized as the name of a cmdlet.

Open your CMD shell and run the following commands.

shell
# ๐Ÿ‘‡๏ธ create a virtual environment python -m venv venv # ๐Ÿ‘‡๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐Ÿ‘‡๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # ๐Ÿ‘‡๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐Ÿ‘‡๏ธ install `django` in the virtual environment pip install django # ๐Ÿ‘‡๏ธ start your `django` project django-admin startproject mysite

install django first

Make sure to use the correct activation command depending on your shell type.

If the python -m venv venv command doesn't work, try the following 2 commands:

  • py -m venv venv
  • python3 -m venv venv

Here is a command that activates a virtual environment named venv and works for both CMD and PowerShell.

shell
# ๐Ÿ‘‡๏ธ universal command for CMD and PowerShell venv\Scripts\activate

If the error persists, try to install django using the following commands.

cmd
pip install Django pip3 install Django pip install Django --user python -m pip install Django py -m pip install Django python3 -m pip install Django

After you have Django installed, you should be able to start a project using the following command.

cmd
django-admin startproject mysite

If the error is not resolved, you have to add Python to your user's PATH environment variable.

# Add Python to your user's PATH environment variable

To add Python to your user's PATH environment variable:

  1. Click on the Search bar and type "environment variables".
  2. Click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. In the "User variables for YOUR_USER" section, select the "Path" variable and click "Edit".

select user path click edit

  1. Click on "New" and then click "Browse".

click new browse

  1. You can use one of the following commands to check where your Python installation is located.
cmd
python -c "import os, sys; print(os.path.dirname(sys.executable))" where python

find python path

For me, the path is the following.

cmd
C:\Users\YOUR_USER\AppData\Local\Programs\Python\Python310

Note that I have Python 3.10 installed, which is reflected in the PATH.

  1. Add the path to Python and then add the path to the Scripts directory that is located in your Python3X folder. This is where the executable files are located.

For me, it is the following path.

cmd
C:\Users\YOUR_USER\AppData\Local\Programs\Python\Python310\Scripts

add scripts folder

  1. Once the two paths are added, confirm the changes by clicking on the "OK" button twice.

added python and pip to path

  1. Close your Command prompt application and then reopen it.
Note that you must restart your Command prompt shell for the changes to take effect.

You might also have to restart your PC, but that's not always necessary.

  1. Try to issue django-admin command after adding Python to your PATH.
shell
# ๐Ÿ‘‡๏ธ create a virtual environment python -m venv venv # ๐Ÿ‘‡๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐Ÿ‘‡๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # ๐Ÿ‘‡๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐Ÿ‘‡๏ธ install `django` in the virtual environment pip install django # ๐Ÿ‘‡๏ธ start your `django` project django-admin startproject mysite

If the error persists, try to add Python to your PATH using the official installer.

  1. Download the installer from the official python.org website.

  2. If you have Python already installed, start the installer and click on "Modify".

click modify

You can leave the optional features ticked.

optional features

  1. On the "Advanced Options" screen, make sure to tick the "Add Python to environment variables" option.

add python to environment variables

  1. Once the "Add Python to environment variables" checkbox is checked, click "Install".
Now your Python installation should be set up correctly and Python should be added to your user's PATH environment variable.

If that didn't work, your Python installation might be corrupted.

Start the installer again and click on "Uninstall".

uninstall python

Now that you don't have Python installed on your machine, start the installer again and make sure to tick the "Add python.exe to PATH" option.

add python exe to path

The checkbox won't be checked by default.

Once the "Add python.exe to PATH" checkbox is checked, click on "Install Now".

After the installation, Python will be installed and configured properly.

# Conclusion

To solve the error "'django-admin' is not recognized as an internal or external command, operable program or batch file", make sure:

  1. You have Django installed before issuing a django-admin command.
  2. You have Python in your user's PATH environment variable.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev