Last updated: Apr 4, 2024
Reading timeยท4 min
The error "'django-admin' is not recognized as an internal or external command, operable program or batch file" occurs for 2 main reasons:
django-admin
command.'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.
# ๐๏ธ 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
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.
# ๐๏ธ universal command for CMD and PowerShell venv\Scripts\activate
If the error persists, try to install django
using the following commands.
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.
django-admin startproject mysite
If the error is not resolved, you have to add Python to your user's PATH environment variable.
To add Python to your user's PATH environment variable:
python -c "import os, sys; print(os.path.dirname(sys.executable))" where python
For me, the path is the following.
C:\Users\YOUR_USER\AppData\Local\Programs\Python\Python310
Note that I have Python 3.10 installed, which is reflected in the PATH.
Scripts
directory that
is located in your Python3X folder. This is where the executable files are
located.For me, it is the following path.
C:\Users\YOUR_USER\AppData\Local\Programs\Python\Python310\Scripts
You might also have to restart your PC, but that's not always necessary.
django-admin
command after adding Python to your PATH.# ๐๏ธ 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.
Download the installer from the official python.org website.
If you have Python already installed, start the installer and click on "Modify".
You can leave the optional features ticked.
If that didn't work, your Python installation might be corrupted.
Start the installer again and click on "Uninstall".
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.
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.
To solve the error "'django-admin' is not recognized as an internal or external command, operable program or batch file", make sure:
django-admin
command.You can learn more about the related topics by checking out the following tutorials: